//WAJP to find Square or Cube according to choice (i.e. 1 for Square, 2 for Cube).
import java.util.*;
class MenuDrivenProgram
{
public static void main()
{
int ch,n,s,c;
Scanner sc=new Scanner(System.in);
System.out.print("Enter any Number to get Square or Cube: ");
n=sc.nextInt();
System.out.println("1. for Square");
System.out.println("2. for Cube");
System.out.print("Enter Your Choice: ");
ch=sc.nextInt();
switch(ch)
{
case 1:
s=n*n;
System.out.println("The Square of " + n + " is "+s);
break;
case 2:
c=n*n*n;
System.out.println("The Cube of " + n + " is "+c);
break;
default:
System.out.println("There is only two choices 1 or 2");
}
}
}
//WAJP to find Addition, Subtraction, Product or Quotient according to choice (i.e. 1 for Addition, 2 for Subtraction, 3 for Product, 4 for Quotient).
class MenuDrivenProgram
{
public static void main()
{
int ch;
float a,b,s,d,p,q;
Scanner sc=new Scanner(System.in);
System.out.print("Enter First Number: ");
a=sc.nextFloat();
System.out.print("Enter Second Number : ");
b=sc.nextFloat();
System.out.println("1. for Addition");
System.out.println("2. for Subtraction");
System.out.println("3. for Product");
System.out.println("4. for Quotient");
System.out.print("Enter Your Choice: ");
ch=sc.nextInt();
switch(ch)
{
case 1:
s = a + b;
System.out.println("The Sum is "+s);
break;
case 2:
d = a - b;
System.out.println("The Difference is "+d);
break;
case 3:
s = a * b;
System.out.println("The Product is "+p);
break;
case 4:
d = a / b;
System.out.println("The Quotient is "+q);
break;
default:
System.out.println("There is only choices from 1 to 4");
}
}
}