-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSumOfTwoInt.java
More file actions
25 lines (21 loc) · 787 Bytes
/
SumOfTwoInt.java
File metadata and controls
25 lines (21 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package learnAdd;
import javax.swing.JOptionPane;
/**
* This program demonstrates exercise 3.4 in page 85
* @author youkpter
*/
public class SumOfTwoInt
{
public static void main(String[] args)
{
int a = (int)(Math.random() * 100);
int b = (int)(Math.random() * 100);
String inputString = JOptionPane.showInputDialog(null, "Please input the sum of " + a + " "+ b,
"SumOfTwoInt", JOptionPane.QUESTION_MESSAGE);
int answer = Integer.parseInt(inputString);
if(answer == (a + b))
JOptionPane.showMessageDialog(null, "true", "SumOfTwoInt", JOptionPane.INFORMATION_MESSAGE);
else
JOptionPane.showMessageDialog(null, "false", "SumOfTwoInt", JOptionPane.INFORMATION_MESSAGE);
}
}