Computer Science, asked by shembrom96, 1 month ago

5. Write a program using menu driven to find the volume of a cube, a sphere and a cuboid.
For an incorrect choice, an appropriate error message should be displayed.
(a) Volume of a cube = s * s *s
(b) Volume of a sphere n*r*r*r ( n = 22/7 )
(C) Volume of a cuboid = 1*b*h​

Answers

Answered by taanyagupta242
1

Explanation:

class shape

{

void main()

{

int vcube=0,vsphere=0,vcuboid=0,s,r,l,b,h,ch;

Scanner sc= new Scanner(System.in);

System.out.print("Enter 1 for volume of cube");

System.out.print("Enter 2 for volume of cube");

System.out.print("Enter 3 for volume of cuboid");

System.out.print("Enter your choice="):

ch=sc.nextInt();

switch(ch)

{

case 1:

System.out.print("Enter the value of s=");

s=sc.nextInt();

vcube=s*s*s;

System.out.println("volume of cube="+vcube);

break;

case 2:

System.out.print("Enter the value of r=");

r=sc.nextInt();

vsphere=22/7*r*r*r;

System.out.println("volume of sphere="+vsphere);

break;

case 3:

System.out.print("Enter the value of l=");

l=sc.nextInt();

System.out.print("Enter the value of b=");

b=sc.nextInt();

System.out.print("Enter the value of h=");

h=sc.nextInt();

vcuboid=l*b*h;

System.out.println("volume of cuboid="+vcuboid);

break;

default:

System.out.println("wrong choice");

}

}

}

Similar questions