Computer Science, asked by hudaabidi786, 2 months ago

Write a menu driven program of addition, subtraction, multiplication,

division and modules using if condition.​

Answers

Answered by anindyaadhikari13
4

Answer:

The given co‎de is written in Java.

import java.util.*;

public class Main   {

   public static void main(String args[])  {

       Scanner sc=new Scanner(System.in);

       int a,b,ch;

       System.out.print("Enter first number: ");

       a=sc.nextInt();

       System.out.print("Enter second number: ");

       b=sc.nextInt();

       System.out.println("\n1. Addition.");

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

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

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

       System.out.println("5. Modulus.");

       System.out.print("\nEnter your choice: ");

       ch=sc.nextInt();

       if(ch==1)

           System.out.println("Sum: "+(a+b));

       else if(ch==2)

           System.out.println("Difference: "+(a-b));

       else if(ch==3)

           System.out.println("Product: "+a*b);

       else if(ch==4)

           System.out.println("Quotient: "+a/b);

       else if(ch==5)

           System.out.println("Remainder: "+a%b);

       else

           System.out.println("Invalid Choice.");

       sc.close();

   }

}

Refer to the attachment for output.

•••♪

Attachments:
Similar questions