Skip to content

Commit

Permalink
Create Switch Case
Browse files Browse the repository at this point in the history
  • Loading branch information
goriblok1235 authored Oct 4, 2023
1 parent 1f70a75 commit 7c0a1eb
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions Switch Case
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import java.util.Scanner;

public class SwitchCase2 {
// Simple Calculator--
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter your first number :");
int a = sc.nextInt();

System.out.println("Enter your second number :");
int b = sc.nextInt();

System.out.println("Which Operation you want to do :");
char op = sc.next().charAt(0);

switch (op) {
case '+':
System.out.printf("Addition of a and b is %d", a + b);
System.out.printf("\n");
break;
case '-':
System.out.printf("Subtraction of a and b is %d", a - b);
System.out.println("\n");
break;

case '*':
System.out.printf("Multiplication of a and b is %d", a * b);
System.out.printf("\n");
break;
case '/':
System.out.printf("Division of a and b is %d", a / b);
System.out.printf("\n");
break;

case '%':
System.out.printf("Mod is %d", a % b);
System.out.printf("\n");
break;

default:
System.out.println("Invalid Operator");
}
sc.close();
}
}

0 comments on commit 7c0a1eb

Please sign in to comment.