/ / Menu Driven Program Perform Arithmetic Operators in Java using Switch Case

Menu Driven Program Perform Arithmetic Operators in Java using Switch Case

In this example, I share menu driven program performs arithmetic operators in java basically, it is a menu driven mini calculator with all arithmetic operators in java. 


arithmetic operators in java


Java code for arithmetic operations 


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;
    }
   }
  }
 }

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 program perform arithmetic operators in java using switch case. Happy Coding 😊
Menu Driven Program Perform Arithmetic Operators in Java using Switch Case Menu Driven Program Perform Arithmetic Operators in Java using Switch Case Reviewed by Veer Bhadra Singh on May 01, 2020 Rating: 5

No comments:

Powered by Blogger.