//****************************************************** // Program Name: spherestats.java // Author: Pat Moss // Date: Sept 17, 2005 Rev: 01 // // Input sphere radius. Then calculate volume and area. //****************************************************** import java.util.Scanner; public class spherestats { public static void main (String[] args) { float sphereradius = 0; Scanner scan = new Scanner(System.in); System.out.println ("spherestats.java by pat moss"); System.out.println (""); System.out.print ("Enter a positive float value for sphere radius (0 to quit): "); sphereradius = scan.nextFloat(); while (sphereradius != 0) // Use the sentinel value of 0 to terminate the loop { if(sphereradius < 0) { System.out.println ("Invalid input value. Please reenter a positive float value."); } else { double spherevolume = (double) 4 / 3 * Math.PI * Math.pow (sphereradius, 3); double spherearea = 4.0D * Math.PI * Math.pow (sphereradius, 2); System.out.println ("The sphere volume is " + spherevolume); System.out.println ("The sphere area is " + spherearea); System.out.println (""); } System.out.println (""); System.out.print ("Enter a positive float value for sphere radius (0 to quit): "); sphereradius = scan.nextFloat(); } System.out.println ("All Done..."); } }