-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.java
More file actions
46 lines (34 loc) · 1.01 KB
/
Calculator.java
File metadata and controls
46 lines (34 loc) · 1.01 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
package com.company;
import javax.xml.crypto.dsig.spec.XSLTTransformParameterSpec;
import java.util.Scanner;
public class Calculator {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter First Number");
int a = sc.nextInt();
System.out.println("Enter Operator");
String b = sc.next();
System.out.println("Enter Second Number");
int c = sc.nextInt();
int sum = a + c ;
int sub = a - c ;
int mul = a * c ;
int div = a / c ;
switch (b) {
case "+" :
System.out.println(sum);
break;
case "-" :
System.out.println(sub);
break;
case "*" :
System.out.println(mul);
break;
case "/" :
System.out.println(div);
break;
default:
System.out.println("error");
}
}
}