Sunday, February 23, 2020

Java Menu Driven Program

Menu-driven program A program that obtains input from a user by displaying a list of options – the menu – from which the user indicates his/her choice.


import java.util.Scanner;
class MenuDrivenExample
{
public static void main(String []args)
{
int a,b,c;
Scanner s=new Scanner(System.in);
System.out.println("   Enter any two number :"  );
a=s.nextInt();
b=s.nextInt();
do
{
System.out.println("  Choose any operation given below"   );
System.out.println("   1.Addition" );
System.out.println("   2.Subtraction " ) ;
System.out.println("   3.Multiplication" );
System.out.println("   4.Division  ");
c=s.nextInt();
switch(c)    {
case 1:        
 System.out.println("   Addition  :"  + (a+b));       
 break;
 case 2:        
 System.out.println("   Subtraction  :"   +(a-b));      
 break;
 case 3:      
 System.out.println("   Multiplication  :"   +(a*b));   
 break;
 case 4:      
 System.out.println("  Division  :"     +(a/b));
 break;
default: 
if (c==0)
System.out.println("   Program End, Try Again ");
else 
System.out.println("   please choose any operation : ");
break;
}}
while(c !=0);
}
}

No comments:

Post a Comment