Write a Java program to create Simple Calculator using switch case.
import java.util.*;
class choice
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.println("Enter your Choice");
System.out.println("Press 1 for Add");
System.out.println("Press 2 for Sub");
System.out.println("Press 3 for Mul");
System.out.println("Press 4 for Div");
System.out.println("Press 5 for Mod");
int choice = in.nextInt();
switch(choice)
{
case 1:
System.out.println("Enter the first number :-");
int a = in.nextInt();
System.out.println("Enter the first number :-");
int b = in.nextInt();
int add = a+b;
System.out.println("The addition of two number is :-"+add);
break;
case 2:
System.out.println("Enter the first number :-");
int c = in.nextInt();
System.out.println("Enter the first number :-");
int d = in.nextInt();
int sub = c-d;
System.out.println("The Substraction of two number is :-"+sub);
break;
case 3:
System.out.println("Enter the first number :-");
int e = in.nextInt();
System.out.println("Enter the first number :-");
int f = in.nextInt();
int mul = e*f;
System.out.println("The Multiplication of two number is :-"+mul);
break;
case 4:
System.out.println("Enter the first number :-");
int g = in.nextInt();
System.out.println("Enter the first number :-");
int h = in.nextInt();
int div = g/h;
System.out.println("The division of two number is :-"+div);
break;
case 5:
System.out.println("Enter the first number :-");
int i = in.nextInt();
System.out.println("Enter the first number :-");
int k = in.nextInt();
int mod = i%k;
System.out.println("The addition of two number is :-"+mod);
break;
default:
System.out.println("Invalid input");
}
}
}
Output :-