Computer Science, asked by yamini2181, 7 months ago

Write a program in Java using switch case in scanner class to find the volume of different solids by taking suitable variables and data types.
1. Volume of a cuboid [v=l*b*h]
2. Volume of a cylinder [v=π*r^2*h]
3.Volume of a cone [v=1/3*π*r^2*h]​

Answers

Answered by keyboardavro
4

Answer:

Explanation:

import java.util.*;

public class Volume

{

public static void main ( String args [] )

{

Scanner in = new Scanner ( System.in ) ;

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

int ch = in.nextInt();

double V ;

switch ( ch )

{

case 1 :

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

int l = in.nextInt();

int b = in.nextInt();

int h = in.nextInt();

V = l * b * h ;

System.out.println ( " Volume of cuboid : " + V ) ;

break ;

case 2 :

System.out.print ( " Enter the radius and height : " );

int r = in.nextInt();

int h = in.nextInt();

V = ( 22 / 7.0 ) * r * r * h ;

System.out.println ( " Volume of the cylinder : " + V ) ;

break ;

case 3 :

System.out.print ( " Enter the radius and height : " );

int r = in.nextInt();

int h = in.nextInt();

V = ( 22 / 7.0 ) * ( 1 / 3.0 ) * r * r * h ;

System.out.println ( " Volume of the cone : " + V ) ;

break ;

default :

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

}

}

}

____________

Similar questions