This is a straightforward problem. This little ditty computes the volume and surface area of a sphere. Java is fun, no?
/**
* SphereProblem reads the radius of a sphere from the user and computes its volume and surface area, then prints them out..
*
* @author (Andrew Samuels)
* @version (02-01-2010)
*/
//import scanner class
import java.util.Scanner;
public class SphereProblem
{
public static void main(String[] args)
{
//initialize variables
double radius; //radius of a sphere
double volume; //volume of a sphere
double area; //area of a sphere
double PI = 3.1415;
//create scanner
Scanner keyboard = new Scanner(System.in);
//input radius from the user
System.out.print("Please enter radius of a sphere: ");
radius = keyboard.nextDouble();
//calculate volume
volume = (4/3)*PI*radius*radius*radius;
//calculate area
area = 4*PI*radius*radius;
//print volume
System.out.println("Volume of sphere is: " + volume);
//print area
System.out.println("Area of sphere is: " + area);
}
}