import java.util.*;
class mini_calculator {
static int a=10;
public static int add(int x,int y)
{
return x+y;
}
public static int sub(int x,int y)
{
return x-y;
}
public static int multi(int x,int y)
{
return x*y;
}
public static float divide(int x,int y)
{
return x/y;
}
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
int x,y,ch,w;
System.out.println(a);
float w1;
while (true){
System.out.println("1. Addition");
System.out.println("2. Subtraction");
System.out.println("3. Multipllication");
System.out.println("4. Division");
System.out.println("Enter Your choice:-");
ch=s.nextInt();
switch (ch){
case 1:
System.out.println("Enter Numbers:-");
x=s.nextInt();
y=s.nextInt();
w=add(x,y);
System.out.println(w);
break;
case 2:
System.out.println("Enter Numbers:-");
x=s.nextInt();
y=s.nextInt();
w=sub(x,y);
System.out.println(w);
break;
case 3:
System.out.println("Enter Numbers:-");
x=s.nextInt();
y=s.nextInt();
w=multi(x,y);
System.out.println(w);
break;
case 4:
System.out.println("Enter Numbers:-");
x=s.nextInt();
y=s.nextInt();
w1=divide(x,y);
System.out.println(w1);
break;
case 5: break;
}
}
}
}
Program Output:
C:\jdk-12.0.2\bin>java mini_calculator 10
1.Addition
2.Subtraction
3.Multipllication
4.Division
Enter Your choice:- 2
Enter Numbers:- 13
3
10
1.Addition
2.Subtraction
3.Multipllication
4.Division
Enter Your choice:- 4
Enter Numbers:- 2
2
1.0
This is all about menu driven Java program to perform arithmetic operators using switch case.
Happy Coding 😊
Tags:
java