Computer Science, asked by Akshat5616, 10 months ago

using switch case to find the volume of a cube, a sphere and a cuboid .For an incorrect
choice, an appropriate error message should be displayed
1. Volume of a cube
=s*s*s
2. Volume of a sphere
=pi*r*T*T
3. Volume of a cuboid
=l*b*h

Answers

Answered by FlyingSaturn
12

Answer:

/*

Using switch case, find the volume of a cube, a sphere and a cuboid .For an incorrect

choice, an appropriate error message should be displayed.

1. Volume of a cube

= s * s * s

2. Volume of a sphere

= 4/3 * pi * r * r * r

3. Volume of a cuboid

= l *b * h

*/

import java.util.*;

class Volume

{

public static void main(String args[])

{

int op;

double s, r, l, b, h, pi = 0.0;

pi = 3.14;

Scanner in = new Scanner(System.in);

System.out.println("Enter 1 for square, 2 for sphere, 3 for cuboid");

op = in.nextInt();

switch(op)

{

case 1 : System.out.println("Enter the side");

s = in.nextDouble();

v = Math.pow(s,3);

System.out.println("Volume" + v);

break;

case 2 : System.out.println("Enter the radius");

r = in.nextDouble();

v = (4.0 /3 )* pi * Math.pow(r,3);

System.out.println("Volume" + v);

break;

case 3 : System.out.println("Enter the length");

l = in.nextDouble();

System.out.println("Enter the breadth");

b = in.nextDouble(); System.out.println("Enter the height");

h = in.nextDouble();

v = l * b * h;

System.out.println("Volume" + v);

break;

default : System.out.println("Wrong Choice!!!");

}

}

}

Answered by shirisha1981
2

Answer:import java.util.*;

class Volume

{

public static void main(String args[])

{

int op;

double s, r, l, b, h, pi = 0.0;

pi = 3.14;

Scanner in = new Scanner(System.in);

System.out.println("Enter 1 for square, 2 for sphere, 3 for cuboid");

op = in.nextInt();

switch(op)

{

case 1 : System.out.println("Enter the side");

s = in.nextDouble();

v = Math.pow(s,3);

System.out.println("Volume" + v);

break;

case 2 : System.out.println("Enter the radius");

r = in.nextDouble();

v = (4.0 /3 )* pi * Math.pow(r,3);

System.out.println("Volume" + v);

break;

case 3 : System.out.println("Enter the length");

l = in.nextDouble();

System.out.println("Enter the breadth");

b = in.nextDouble(); System.out.println("Enter the height");

h = in.nextDouble();

v = l * b * h;

System.out.println("Volume" + v);

break;

default : System.out.println("Wrong Choice!!!");

}

}

}

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

Similar questions