Declare method sphereVolume to calculate and return the volume of the sphere. Use the following statement to calculate the volume:

```
double volume = (4.0 / 3.0) * Math.PI * Math.pow(radius, 3)
```
Write a Java application that prompts the user for the double radius of a sphere, calls sphereVolume
to calculate the volume and displays the result.

The following solution calculates the volume of a sphere, using the radius entered by the user:
```
// Sphere.java
// Calculate the volume of a sphere.
import java.util.Scanner;

public class Sphere {
// obtain radius from user and display volume of sphere
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

System.out.print("Enter radius of sphere: ");
double radius = input.nextDouble();

System.out.printf("Volume is %f%n", sphereVolume(radius));
}

// calculate and return sphere volume
public static double sphereVolume(double radius) {
double volume = (4.0 / 3.0) * Math.PI * Math.pow(radius, 3);
return volume;
}
}
```

Enter radius of sphere: 4
Volume is 268.082573

Computer Science & Information Technology

You might also like to view...

________ is the actual amount of data that is transmitted.

a. Bandwidth b. Throughput c. Broadband d. Streaming

Computer Science & Information Technology

A system can easily be completely secure

Indicate whether the statement is true or false

Computer Science & Information Technology