Reputation: 37
import javax.swing.JOptionPane;
public class Result
{
public static void main (String[] args)
{
int numa;
int numb;
int sum;
String num1 = JOptionPane.showInputDialog(null,"Enter 1st Number: ");
numa=Integer.parseInt(num1);
String num2 = JOptionPane.showInputDialog(null,"Enter 2nd Number: ");
numb=Integer.parseInt(num2);
{
sum=num1+num2;
}
if (sum>=10)
JOptionPane.showMessageDialog(null,"Congratulations"+sum);
else if(sum<10)
JOptionPane.showMessageDialog(null,"the sum of the number less than 10");
else if(sum>100)
System.exit(7);
}
}
Upvotes: 0
Views: 150
Reputation: 1503469
This line:
sum=num1+num2;
is trying to add two strings together and make an int
.
Instead, you want:
sum = numa + numb;
In other words, take the values you've just parsed from the strings, and add those together.
Additionally, I'd suggest:
sum
line) but...if
blocks for clarityUpvotes: 4
Reputation: 7324
sum = numa + numb
You were trying to add the two strings.
Edit: skeeted again!
Upvotes: 2