Computer Science, asked by karanankit, 1 year ago

Write a program using switch case to find the volume of cube, cuboid ,sphere and for an inappropriate choice display a proper error message

Answers

Answered by Debarghya
79
import Java. until. Scanner;
class choice
{
public static void main()
{
System. out. println ("press 1 for cube\npress2 for cuboid");
Scanner SC = new Scanner(System.in);
int a=sc.nextInt();
switch(a)
{
case 1:
System. out. println ("Enter the length of cube");
int l=sc.nextInt();
System. out. println ("volume is "+(l*l*l));
break;
case 2:
System. out. println ("Enter the length,breadth and height");
int ll=sc.nextInt();
int b=sc.nextInt();
int h=sc.nextInt();
System. out. println ("volume is"+(ll*b*h));
break;
default:
System. out. println ("invalid choice ");
}
}
}
Answered by shirisha1981
12

Answer:import Java. until. Scanner;

class choice

{

public static void main()

{

System. out. println ("press 1 for cube\npress2 for cuboid");

Scanner SC = new Scanner(System.in);

int a=sc.nextInt();

switch(a)

{

case 1:

System. out. println ("Enter the length of cube");

int l=sc.nextInt();

System. out. println ("volume is "+(l*l*l));

break;

case 2:

System. out. println ("Enter the length,breadth and height");

int ll=sc.nextInt();

int b=sc.nextInt();

int h=sc.nextInt();

System. out. println ("volume is"+(ll*b*h));

break;

default:

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

}

}

}

Read more on Brainly.in - https://brainly.in/question/1423742#readmore

Similar questions