//********************************************************** // Program Name: poundstokg.java * // Author: Pat Moss * // Date: Sept 26, 2005 Rev: 01 * // * // Convert input Pounds to Kilograms to two decimal places * //********************************************************** import java.util.Scanner; import java.text.DecimalFormat; public class poundstokg { public static void main (String[] args) { final double POUNDSTOKG = 0.453592; // 1 pound = 0.453592 kg double inputpounds = 0.0; double kilograms = 0.0; // Round the output value to two decimal places DecimalFormat fmt = new DecimalFormat ("0.##"); Scanner scan = new Scanner(System.in); System.out.println ("poundstokg.java by pat moss"); System.out.println (""); System.out.print ("Enter a positive double value for pounds (0 to quit): "); inputpounds = scan.nextDouble(); while (inputpounds != 0) // Use the sentinel value of 0 to terminate the loop { if(inputpounds < 0) { System.out.println ("Invalid input value. Please reenter a positive double value."); } else { kilograms = POUNDSTOKG * inputpounds; System.out.print ("The equivalent weight in kg is "); System.out.print (fmt.format(kilograms)); System.out.println (""); } System.out.println (""); System.out.print ("Enter a positive double value for pounds (0 to quit): "); inputpounds = scan.nextDouble(); } System.out.println ("All Done..."); } }