In: Computer Science
import java.util.*;
public class volumeCalculator
{
static double pi = (22.0)/(7.0)
public static double sphere(double radius)
{
double vs = (4.0/3.0)*pi*radius*radius*radius;
return vs;
}
public static double cylinder(double radius, double height)
{
double vc = pi*radius*radius*height;
return vc;
}
public static double cube(double side)
{
double vc = side*side*side;
return vc;
}
public static double box(double length, double breadth, double height)
{
double vb = length*breadth*height;
return vb;
}
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
double radius = sc.nextDouble();
volSphere = sphere(radius);
System.out.println(volSphere);
double height = sc.nextDouble();
volCylinder = cylinder(radius, height);
System.out.println(volCylinder);
double side = sc.nextDouble();
volSide = cube(side);
System.out.println(volSide);
double length = sc.nextDouble();
double breadth = sc.nextDouble();
double height = sc.nextDouble();
volBox = box(length, breadth, height);
System.out.println(volBox);
}
}
Please find the solution code above, and comment if found any issue, it will be resolved as soon as possible. Thank you.