-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCalculator.java
More file actions
61 lines (31 loc) · 765 Bytes
/
Calculator.java
File metadata and controls
61 lines (31 loc) · 765 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
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
import java.util.Scanner;
public class Calculator {
public static void main(String[] args) {
// Create a Scanner
Scanner input = new Scanner(System.in);
System.out.println("If x = 50 and y = 2");
System.out.println("Please select the operator 1.plus 2.subtract 3.multiply 4.division");
System.out.print("Enter:");
double answer = 0;
int x = 50;
int y = 2;
int menu = input.nextInt();
switch (menu) {
case 1:answer = x+y;
System.out.print("Answer is "+answer);
break;
case 2:answer = x-y;
System.out.print("Answer is "+answer);
break;
case 3:answer = x*y;
System.out.print("Answer is "+answer);
break;
case 4:answer = x/y;
System.out.print("Answer is "+answer);
break;
default:
System.out.println("You put invalid choice");
break;
}
}
}