Skip to content

Commit d3f6d41

Browse files
committed
feat: Implement switch-case arithmetic calculator for two integers
🧠 Logic: - Reads two integers and a character operator as input. - Uses a `switch` statement to determine which arithmetic operation to perform: +, -, *, or /. - For valid operators, prints the result of the operation. - If the operator is not recognized, prints "Invalid operator". - Division assumes non-zero denominator as guaranteed by problem constraints. Signed-off-by: Somesh diwan <someshdiwan369@gmail.com>
1 parent d1c8d1b commit d3f6d41

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

Section7ConditionalStatements/src/SwitchCodeCC2.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
Arithmetic operation:
33
4-
Write a C++ program that takes two numbers and an operator (+, -, *, /) as input.
4+
Write a JAVA program that takes two numbers and an operator (+, -, *, /) as input.
55
66
Use a 'switch' statement to perform the corresponding arithmetic operation and print the result.
77
@@ -18,7 +18,7 @@ public static void main(String[] args) {
1818
int num1 = scanner.nextInt();
1919
int num2 = scanner.nextInt();
2020

21-
//Take two integer as a input and choose a one operator's below this.
21+
//Take two integers as an input and choose a one operator's below this.
2222
char op = scanner.next().charAt(0);
2323

2424
switch (op) {
@@ -38,4 +38,4 @@ public static void main(String[] args) {
3838
System.out.println("Invalid operator");
3939
}
4040
}
41-
}
41+
}

0 commit comments

Comments
 (0)