Posted by Thanh on Tuesday, July 14, 2009 at 6:46pm.
The Scanner method for reading in an int is nextInt().
You need to instantiate a Scanner, and replace the inputs and outputs.
firstNum = JOptionPane.showInputDialog("Enter first integer: " );
secondNum = JOptionPane.showInputDialog("Enter second integer: " );
using a Scanner, you will have
// instantiate scanner
Scanner kb = new Scanner(System.in);
// output dialog
out.print("Enter first integer: ");
// input int
firstNum = kb.nextInt();
// second int
out.print("Enter second integer: ");
secondNum = kb.nextInt();
Now you need to change your output.
JOptionPane.showMessageDialog(null, "The sum is " + sum,
include simple printlines.
System.out.println("The sum is "+sum);
And do the same for the rest of the output.
Java help please - I am trying to run the following program and am getting this ...
java - Write a java application that finds the smallest of several integers. ...
programming - I am supposed to modify this program so it begins by asking the ...
java - can anyone help me with this? I'm new to java! Write a program that ...
programming - Having troube with java, i am not a regular programmer, if anybody...
Java - I am trying to write an algorithm for my JAVA class and am having some ...
Computer Science-Java - Hi, I am writing an application class for a Lunar ...
Computer Sciene-java - Write a loop that will continuously prompt the user for ...
Computer Science - Java - Hi, For an assignment I am doing, we have to have 2 ...
programming - write a program that maintains two parallel arrays. after th ...
For Further Reading