Computer Science, asked by rehanbarkaati09, 2 months ago

.Write Menu Driven java program for Calculator (1. Add, 2. Sub, 3.

Product, 4. Division, 5. Modulus) by taking user choice as input.​

Answers

Answered by Anonymous
0

Answer:

i am using Scanner class

Explanation:

import java.util.Scanner;

public class menu

{

public static void main()

{

Scanner sc = new Scanner(System.in);

System.out.println("---------------MENU--------------");

System.out.println("1. Add");

System.out.println("2. Subtract");

System.out.println("3.Multiply");

System.out.println("4. Divide");

int ch = sc.nextInt();

switch(ch)

{

case 1:

{

System.out.println("Enter first number");

int a = sc.nextInt();

System.out.println("Enter second number");

int b = sc.nextInt();

int c = a+b;

System.out.println("On adding "+a+" and "+b+" you get: "+c);

}

break;

case 2:

{

System.out.println("Enter first number");

int a = sc.nextInt();

System.out.println("Enter second number");

int b = sc.nextInt();

int c = a-b;

System.out.println("On subtracting "+a+" and "+b+" you get: "+c);

}

break;

case 3:

{

System.out.println("Enter first number");

int a = sc.nextInt();

System.out.println("Enter second number");

int b = sc.nextInt();

int c = a*b;

System.out.println("On multiplying "+a+" and "+b+" you get: "+c);

}

break;

case 4:

{

System.out.println("Enter first number");

int a = sc.nextInt();

System.out.println("Enter second number");

int b = sc.nextInt();

int c = a/b;

System.out.println("On dividing "+a+" and "+b+" you get: "+c);

}

break;

default:

{

System.out.println("Wrong choice");

}

}

}

}

Similar questions