1  // Application to calculate sphere volumes - shows syntax of methods
  2  
  3  import java.io.*;
  4  
  5  public class Volume
  6  {
  7     static private double radius,volume;
  8  
  9     public static void main (String[] args)
 10     {
 11        /* uses method from Console class to read formatted input -
 12  		prints the argument as a prompt, then reads a double
 13  		terminated by a newline */
 14  
 15        radius = Console.readDouble("Type in the radius of the sphere: ");
 16        volume = sphereVolume(radius);
 17  
 18        System.out.println("Volume is " + volume + "\n");
 19     }
 20  
 21     // this method is called locally with one argument of type double
 22     // and returns a double
 23  
 24     static private double sphereVolume(double rad)
 25     {
 26        double vol;
 27        vol = (4.0/3.0) * Math.PI * Math.pow(rad,3);
 28        return vol;
 29     }
 30      
 31  }
 32