-
Notifications
You must be signed in to change notification settings - Fork 605
Open
Description
import java.util.Scanner;
public class Main{
public static void main (String []args){
int Operator,n1,n2;
System.out.println("1-Add\n2-Subtract\n3-Multiply\n4-Divide\n5-Modulus");
System.out.print("Choose the operator: ");
Scanner sc=new Scanner(System.in);
Operator=sc.nextInt();
System.out.print("Enter the first number: ");
n1=sc.nextInt();
System.out.print("Enter the second number: ");
n2=sc.nextInt();
int Result=0;
switch(Operator){
case 1:
Result=n1+n2;
break;
case 2:
Result=n1-n2;
break;
case 3:
Result=n1*n2;
break;
case 4:
Result=n1/n2;
break;
case 5:
Result=n1%n2;
break;
default:
System.out.println("Entered value is invalid");
}System.out.println("The result is " + Result);
}
}
Metadata
Metadata
Assignees
Labels
No labels