-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstatementswitch.java
More file actions
48 lines (44 loc) · 1.55 KB
/
statementswitch.java
File metadata and controls
48 lines (44 loc) · 1.55 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
import java.util.Scanner;
public class statementswitch {
static Scanner in = new Scanner(System.in);
public static void main(String[] args) {
float num1, num2;
double total;
char operator;
System.out.print("Enter first number: ");
num1 = in.nextFloat();
System.out.print("Enter second number: ");
num2 = in.nextFloat();
System.out.println("Enter the Operator:" + "\n"
+ "[A] Addition" + "\n" + "[B] Subtraction" + "\n"
+ "[C] Multiplication" + "\n" + "[D] Division");
System.out.println(" ");
System.out.println("The answer is: ");
operator = in.next().charAt(0);
switch (operator) {
case 'A':
case 'a':
total = num1 + num2;
System.out.println(num1+" "+" + "+" "+num2+" = "+" "+ total);
break;
case 'B':
case 'b':
total = num1 - num2;
System.out.println(num1+" "+" - "+" "+num2+" = "+" "+ total);
break;
case 'C':
case 'c':
total = num1 * num2;
System.out.println(num1+" "+" * "+" "+num2+" = "+" "+ total);
break;
case 'D':
case 'd':
total = num1 / num2;
System.out.println(num1+" "+" /"+" "+num2+" = "+" "+ total);
break;
default:
System.out.println("Sorry Wrong input! Please Try Again!");
break;
}
}
}