-
Notifications
You must be signed in to change notification settings - Fork 0
/
ass6.java
51 lines (48 loc) · 2.2 KB
/
ass6.java
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import javax.swing.JOptionPane;
public class ass6 {
public static void main(String args[]) {
int button = 0;
while (button != 5) {
String number1, number2;
double a, b, ans;
String opt = JOptionPane.showInputDialog("1.addition\n 2.subtraction\n 3.multiplication\n 4.division\n -99.exit");
button = Integer.parseInt(opt);
switch (button) {
case 1:
number1 = JOptionPane.showInputDialog("enter first decimal number");
number2 = JOptionPane.showInputDialog("enter first decimal number");
a = Double.parseDouble(number1);
b = Double.parseDouble(number2);
ans = a + b;
JOptionPane.showMessageDialog(null, ans);
break;
case 2:
number1 = JOptionPane.showInputDialog("enter first decimal number");
number2 = JOptionPane.showInputDialog("enter first decimal number");
a = Double.parseDouble(number1);
b = Double.parseDouble(number2);
ans = a - b;
JOptionPane.showMessageDialog(null, ans);
break;
case 3:
number1 = JOptionPane.showInputDialog("enter first decimal number");
number2 = JOptionPane.showInputDialog("enter first decimal number");
a = Double.parseDouble(number1);
b = Double.parseDouble(number2);
ans = a * b;
JOptionPane.showMessageDialog(null, ans);
break;
case 4:
number1 = JOptionPane.showInputDialog("enter first decimal number");
number2 = JOptionPane.showInputDialog("enter first decimal number");
a = Double.parseDouble(number1);
b = Double.parseDouble(number2);
ans = a / b;
JOptionPane.showMessageDialog(null, ans);
break;
case -99:
System.exit(0);
}
}
}
}