Write a menu driven program of addition, subtraction, multiplication,
division and modules using if condition.
Answers
Answer:
The given code 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.
•••♪