72.5k views
17 votes
Given sphereRadius and piVal, compute the volume of a sphere and assign sphereVolume with the result. Use (4.0 / 3.0) to perform floating-point division, instead of (4 / 3) which performs integer division.

Volume of sphere = (4.0 / 3.0) Ï r3 (Hint: r3 can be computed using *)
import java.util.Scanner;
public class SphereVolumeCalculator {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
double piVal = 3.14159;
double sphereVolume;
double sphereRadius;
sphereRadius = scnr.nextDouble();
*insert code*
System.out.println(sphereVolume);
}
}

User Fjanisze
by
6.6k points

1 Answer

11 votes

Answer:

The code to this question can be defined as follows:

sphereVolume = (4.0/3.0)*piVal*sphereRadius*sphereRadius*sphereRadius; // defining a double variable sphereVolume that calculate and hold its value

Step-by-step explanation:

Please find the complete code in the attachment file.

In the code, a class "SphereVolumeCalculator" is declared, and inside the main method Three double variable "piVal, sphereRadius, and sphereVolume" , in which "piVal" is used to hold a value, in the next step scanner class object is created for holding the "shereRadius" value and the sphereVolume is used for calculate and print its value.

Given sphereRadius and piVal, compute the volume of a sphere and assign sphereVolume-example-1
User Mel Padden
by
7.2k points