-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCalculator.java
More file actions
35 lines (35 loc) · 1.09 KB
/
Copy pathCalculator.java
File metadata and controls
35 lines (35 loc) · 1.09 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
import java.util.*;
public class Calculator {
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number");
int A = sc.nextInt();
System.out.println("Enter another number");
int B = sc.nextInt();
System.out.println("Enter ur choice");
String choice = sc.next();
switch(choice){
case "+":
System.out.println(A + B);
break;
case "-":
System.out.println(A - B);
break;
case "*":
System.out.println(A * B);
break;
case "/":
if(B !=0){
System.out.println(A/B);
break;
}
else{
System.out.println("Can you choose B value other than 0");
break;
}
default:
System.out.println("It is an invalid option! try again...");
}
sc.close();
}
}