Skip to content

Commit 542ee01

Browse files
committed
feat: Implement menu-driven arithmetic calculator using switch-case and string input
🧠 Logic: - Displays a menu with options: ADD, SUB, MUL, DIV. - Takes two integer inputs from the user. - Reads arithmetic operation as a string and converts it to uppercase for case-insensitive comparison. - Uses a `switch-case` on the entered option to: - Perform addition, subtraction, multiplication, or division. - Print the corresponding result. - If the input is invalid, it shows an "Invalid Option" message. Signed-off-by: Somesh diwan <[email protected]>
1 parent e1f7262 commit 542ee01

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

Section7ConditionalStatements/src/SwitchCasesIMPAB.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ public static void main(String[] args) {
2626
String option=sc.nextLine();
2727
option=option.toUpperCase();
2828

29-
switch(option)
30-
{
29+
switch(option) {
3130
case "ADD": System.out.println("Sum is "+(x+y));
3231
break;
3332
case "SUB": System.out.println("Difference is "+(x-y));
@@ -36,9 +35,8 @@ public static void main(String[] args) {
3635
break;
3736
case "DIV": System.out.println("Ratio is "+(x/y));
3837
break;
39-
default: System.out.println("Invalid Option");
38+
default: System.out.println("Invalid Option");
4039
break;
4140
}
4241
}
4342
}
44-

0 commit comments

Comments
 (0)