Write a program to accept two numbers from user and print addition,Subtraction,Multiplication and Division as per choice selected by by user in java
Write a program to accept two numbers from user and print addition,Subtraction,Multiplication and
Division as per choice selected by by user.
import java.util.Scanner;
class Menu
{
public static void main(String args[])
{
int a,b,c,ch;
Scanner s=new Scanner(System.in);
System.out.println("1.Add/n2.Sub/n3.Mult/n4.Div");
System.out.println("Enter two no");
a=s.nextInt();
b=s.nextInt();
System.out.println("Enter your Choise");
ch=s.nextInt();
switch(ch)
{
case 1:
c=a+b;
System.out.println("Add is "+c);
break;
case 2:
c=a-b;
System.out.println("Sub is "+c);
break;
case 3:
c=a*b;
System.out.println("Mul is "+c);
break;
case 4:
c=a/b;
System.out.println("Div is "+c);
break;
default:
System.out.println("Invalid choise");
break;
}
}
}
Output:
Division as per choice selected by by user.
import java.util.Scanner;
class Menu
{
public static void main(String args[])
{
int a,b,c,ch;
Scanner s=new Scanner(System.in);
System.out.println("1.Add/n2.Sub/n3.Mult/n4.Div");
System.out.println("Enter two no");
a=s.nextInt();
b=s.nextInt();
System.out.println("Enter your Choise");
ch=s.nextInt();
switch(ch)
{
case 1:
c=a+b;
System.out.println("Add is "+c);
break;
case 2:
c=a-b;
System.out.println("Sub is "+c);
break;
case 3:
c=a*b;
System.out.println("Mul is "+c);
break;
case 4:
c=a/b;
System.out.println("Div is "+c);
break;
default:
System.out.println("Invalid choise");
break;
}
}
}
Output:
Comments
Post a Comment
If you have any query, please let us know