SWITCH CASE- CALCULATOR
One of the most important programs of the switch case is the calculator and it can be asked in boards also. We are well aware about the calculator. Calculator is something which makes our work easier by doing the long calculations. So here is the simple calculator program using the SWITCH CASE.
PROGRAM
import java.io.*;
import java.util.*;
class calculator
{
public void main()throws IOException
{
int a, b;
Scanner sc=new Scanner(System.in);
System.out.println("Input the a : ");
a=sc.nextInt();
System.out.println("Input the b : ");
b=sc.nextInt();
int opt;
System.out.println("MAIN MENU ");
System.out.println("1--> Addition");
System.out.println("2--> Subtraction");
System.out.println("3--> Multiplication ");
System.out.println("4--> Division ");
opt=sc.nextInt();
switch(opt)
{
case 1 :
int c=a+b;
System.out.println("Sum = "+c); break;
case 2 : int d=0;
d=a-b;
System.out.println("Subtracttion = "+d);
break;
case 3: int m=a*b;
System.out.println("Multiplication = "+m);
break;
case 4 : int div=a/b;
System.out.println("Division = "+div);
break;
default : System.out.println("Wrong choice entered :- ");
}
}
}