-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.java
More file actions
38 lines (32 loc) · 1.12 KB
/
Copy pathcalculator.java
File metadata and controls
38 lines (32 loc) · 1.12 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
import java.util.*;
public class calculator {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int sum, subtract, multiply, division;
System.out.println("Enter the first value: ");
int a = sc.nextInt();
System.out.println("Enter the second value: ");
int b = sc.nextInt();
System.out.println("Press the following\n1.Sum 2.Subtract 3.Multiply 4.Division");
int operator = sc.nextInt();
sc.close();
switch (operator) {
case 1:
sum = a + b;
System.out.println("Sum is " + sum);
break;
case 2:
subtract = a - b;
System.out.println("Subtraction is " + subtract);
break;
case 3:
multiply = a * b;
System.out.println("Multiplication is " + multiply);
break;
case 4:
division = a / b;
System.out.println("Division is " + division);
break;
}
}
}