-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCalculator_nin.java
More file actions
66 lines (51 loc) · 1.73 KB
/
Calculator_nin.java
File metadata and controls
66 lines (51 loc) · 1.73 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import java.util.Scanner;
public class Calculator_nin {
public static double add(double x, double y) {
return x + y;
}
public static double subtract(double x, double y) {
return x - y;
}
public static double multiply(double x, double y) {
return x * y;
}
public static double divide(double x, double y) {
return x / y;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double[] num = new double[10];
int counter = 0;
while (counter < 10) {
System.out.println("Enter the first number");
double x = scanner.nextDouble();
System.out.println("Enter the second number");
double y = scanner.nextDouble();
System.out.println("Enter your equation (+ - * /)");
String equ = scanner.next();
if (equ.equals("-")) {
num[counter] = subtract(x, y);
System.out.println("The answer is:" + num[counter]);
}
else if (equ.equals("+")) {
num[counter] = add(x, y);
System.out.println("The answer is:" + num[counter]);
}
else if (equ.equals("/")) {
num[counter] = divide(x, y);
System.out.println("The answer is:" + num[counter]);
}
else if (equ.equals("*")) {
num[counter] = multiply(x, y);
System.out.println("The answer is:" + num[counter]);
}
else if (equ.equals("q")) {
break;
}
counter++;
}
for (Double num2 : num) {
System.out.println(num2);
}
}
}