-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHwQCalculatorUi.java
More file actions
52 lines (42 loc) · 1.47 KB
/
Copy pathHwQCalculatorUi.java
File metadata and controls
52 lines (42 loc) · 1.47 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
import java.util.Scanner;
public class HwQCalculatorUi {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a Number:");
double a = sc.nextDouble();
System.out.print("Enter a Number:");
double b = sc.nextDouble();
System.out.println("Choose An Operator :");
System.out.println("+ : Addition :");
System.out.println("- : Subtraction :");
System.out.println("* : Multiplication :");
System.out.println("/ : Division :");
System.out.println("% : Modulo :");
System.out.println("Enter The Operator :");
char op = sc.next().charAt(0);
switch (op) {
case '+':
System.out.println("Answer :" + (a + b));
break;
case '-':
System.out.println("Answer :" + (a - b));
break;
case '*':
System.out.println("Answer :" + (a * b));
break;
case '/':
if(b != 0){
System.out.println("Answer :" + (a / b));
}else{
System.out.println("Cannot Divide By Zero ..");
}
case '%':
System.out.println("Answer :" + (a % b));
break;
default:
System.out.println("Invaild Operator.");
break;
}
sc.close();
}
}