Tuesday, 29 August 2017

Java program to enter two numbers and perform operations using switch case

Java program to enter two numbers and perform mathematical operations using switch case

Program

import java.util.Scanner;

class CalC{
          public static void main(String []args){
                   Scanner s = new Scanner(System.in);
                   int a,b;
                   System.out.println("Enter Tow Number...");
                   a = s.nextInt();
                   b = s.nextInt();
                  
                   System.out.println("1.Addition");
                   System.out.println("2.Substraction");
                   System.out.println("3.Multiplication");
                   System.out.println("4.Division");
                   System.out.println("5.Modulo");
                   System.out.print("Chose Any one");
                   int c = s.nextInt();
                  
                   switch(c){
                             case 1:
                             a = a + b;
                             System.out.println("Addition is : "+a);
                             break;
                            
                             case 2:
                             a = a - b;
                             System.out.println("Substraction is : "+a);
                             break;
                            
                             case 3:
                             a = a * b;
                             System.out.println("Multiplication is : "+a);
                             break;
                            
                             case 4:
                             a = a / b;
                             System.out.println("Division is : "+a);
                             break;
                            
                             case 5:
                             a = a % b;
                             System.out.println("Modulo is : "+a);
                             break;
                            
                             default :
                             System.out.println("Enter Right Choise");
                             break;
                   }
          }

}

Output

mathematical operations java core

0 comments:

Post a Comment