OK so i just started taking this begginer Java Class. My professor asked us to write a GUI program thar asks a user to input 2 number and then output the sum. I was able to do that fine. BUt now she has asked use to convert the integers to double... How would i do that? here is my code:
import javax.swing.JOptionPane; // import class JOptionPane
public class Addition2
{
// main method begins execution of Java application
public static void main( String args[] )
{
String number;
int num1;
int num2;
int sum;
// Read first number
number =
JOptionPane.showInputDialog("Please Enter First number:");
num1 = Integer.parseInt(number);
// Read second number
number =
JOptionPane.showInputDialog("Please Enter Second number:");
num2 = Integer.parseInt(number);
//Conver numbers from string to parseint
// Compute SUM
sum = num1 + num2;
String message =
String.format("The sum of the numbers are: %d", sum);
JOptionPane.showMessageDialog( null, message );
}
} // end method main