This is as far as I can get it now, below, I have compile errors, datatype
mismatch (maybe b/v of string args) and a problem with the double.parse, I
dont know enough to mod the code further w/o making a mess, I know its
close.
import javax.swing.*; // Make Swing available
public class sum2 extends java.lang.Object
{
public sum2() { // Creates new main
}
public static void main (String args[])
{
double num1 = JOptionPane.showInputDialog("Input the first number:");
num1 = double.parseDouble(num1)
double num2 = JOptionPane.showInputDialog("Input the second number:");
num2 = double.parseDouble(num2)
double numSum; // Holds the sum
numSum = num1 + num2; // Compute sum
JOptionPane.showMessageDialog(null, "The total is " + numSum);
// Show user the sum in a message window
System.exit(0); // Stops the execution
}
}
"Basil Fawlty" <Ba***************@NOSPAMyahoo.com> wrote in message
news:VI********************@comcast.com...
Hi, I hacked on this one a bit and noticed it has some errors, the
compiler doesnt like the datatypes. Then I noticed I should have
mentioned the recommeded approach that is suggested to use I should have
made mention of earlier, sorry about that. So I tried to incorporatte
what you suggested below with the recommendation, and made a mess out of
it. Here is the recomended approach to apply to the good code to modify:
(BTW, int seemed like a good idea, why double over int?)
String input;
double number1;
input = JoptionPane.showInputDialog("Enter a number");
number1 = Double.parseDouble(input);
I'm to weld into this existig program that does compile fine:
import javax.swing.*; // Make Swing available
public class sum2 extends java.lang.Object
{
public sum2() { // Creates new main
}
public static void main (String args[])
{
int intSum; // Holds the sum
intSum = 14 + 35; // Compute sum
JOptionPane.showMessageDialog(null, "The total is " + intSum); // Show
user the sum in a message window
System.exit(0); // Stops the execution
}
}
"sgt_sock" <sg*****@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
try this:
import javax.swing.*; // Make Swing available
public class sum2 extends java.lang.Object
{
public sum2() { // Creates new main
}
public static void main (String args[])
{
int num1 = JOptionPane.showInputDialog("Input the first number:");
int num2 = JOptionPane.showInputDialog("Input the second number:");
int intSum; // Holds the sum
intSum = num1 + num2; // Compute sum
JOptionPane.showMessageDialog(*null, "The total is " + intSum);
// Show
user the sum in a message window
System.exit(0); // Stops the execution
}