// Application to calculate sphere volumes - shows syntax of methods import java.io.*; public class VolumeStr { static private double radius,volume; public static void main (String[] args) throws IOException { // set up input stream BufferedReader in = new BufferedReader ( new InputStreamReader ( System.in )); System.out.print("Type in the radius of the sphere: "); // read string, trim white space, convert to Double, convert to double radius = (new Double (in.readLine().trim())).doubleValue(); volume = sphereVolume(radius); System.out.println("Volume is " + volume + "\n"); } // this method is called locally with one argument of type double // and returns a double static private double sphereVolume(double rad) { double vol; vol = (4.0/3.0) * Math.PI * Math.pow(rad,3); return vol; } }