-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.java
More file actions
30 lines (26 loc) · 1.05 KB
/
app.java
File metadata and controls
30 lines (26 loc) · 1.05 KB
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
import javax.swing.JOptionPane;
public class app {
public static void main(String[] args) {
String f = "";
int n = Integer.parseInt(JOptionPane.showInputDialog(null, "Type the number to be used in your calculator", "Simple calc", 1));
int p = Integer.parseInt(JOptionPane.showInputDialog(null, "1-Add \n 2- Subtraction \n 3-Multiply \n 4- Divide", "Simple calc", 1));
for (int r = 1; r < 11; r++) {
switch (p) {
case 1:
f += n + " + " + r + " = " + (n + r + "\n");
break;
case 2:
f += n + " - " + r + " = " + (n - r + "\n");
break;
case 3:
f += n + " x " + r + " = " + (n * r + "\n");
break;
case 4:
double result = (double) n / r;
f += (n + " / " + r + " = " + result + "\n");
break;
}
}
JOptionPane.showMessageDialog(null, "The result is: \n" + f);
}
}