-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculatorUsingSwitch.java
More file actions
33 lines (29 loc) · 1.02 KB
/
calculatorUsingSwitch.java
File metadata and controls
33 lines (29 loc) · 1.02 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
import java.util.Scanner;
public class calculatorUsingSwitch {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Input
System.out.print("Enter the first number: ");
int a = sc.nextInt();
System.out.print("Enter the operation (+, -, *, /): ");
char op = sc.next().charAt(0);
System.out.print("Enter the second number: ");
int b = sc.nextInt();
switch(op) {
case '+':
System.out.println("Result: " + (a + b));
break;
case '-':
System.out.println("Result: " + (a - b));
break;
case '*':
System.out.println("Result: " + (a * b));
break;
case '/':
System.out.println("Result: " + (a / b));
break;
default:
System.out.println("Error: Invalid operation. Please enter +, -, *, or /.");
}
}
}