import java.util.Scanner; /* Java application that produces a Fahrenheit-to-Celsius conversion table. ** The user provides as input (via the keyboard) the floor and ceiling ** Fahrenheit temperatures and the "delta" (the amount by which each line's ** Fahrenheit temperature exceeds that of the previous line). ** (The previous version converted a single Fahrenheit temperature rather ** than producing a table of conversions.) ** ** Author: R. McCloskey ** Date: Mar. 2015 */ public class FahToCel3 { public static void main(String[] args) { // Create a new Scanner object that can read input from the keyboard. Scanner keyboard = new Scanner(System.in); double fahFloor; // first Fah. temp. in the table double fahDelta; // increase in Fah. temp. from one row to next double fahCeil; // upper bound on Fah. temp.'s in the table // Prompt user for each input value, and read them. System.out.print("Enter Fahrenheit floor temperature: "); fahFloor = keyboard.nextDouble(); System.out.print("Enter Fahrenheit delta: "); fahDelta = keyboard.nextDouble(); System.out.print("Enter Fahrenheit ceiling: "); fahCeil = keyboard.nextDouble(); // Print table's column headings. System.out.println("Fahrenheit Celsius"); System.out.println("---------- ---------"); // Produce the body of the table. Each loop iteration produces // a single row. for (double fah = fahStart; fah <= fahCeil; fah = fah + fahDelta) { double celTemp = fahToCel(fah); System.out.println(fah + "F " + celTemp + "C"); } } /* Returns the Celsius equivalent of the given Fahrenheit temperature (f). */ private static double fahToCel(double f) { return (5.0 / 9.0) * (f - 32); } }