import java.util.Scanner; /* Java application that converts a particular Fahrenheit temperature ** (provided by the user as an input via the keyboard) to its equivalent ** on the Celsius scale. (This improves the previous version, in which ** the Fahrenheit temperature was "hard-coded" into the program.) ** ** Author: R. McCloskey ** Date: Mar. 2015 */ public class FahToCel2 { public static void main(String[] args) { // Create a new Scanner object that can read input from the keyboard. Scanner keyboard = new Scanner(System.in); // Prompt user to enter a Fahrenheit temp.; then read the response System.out.print("Enter Fahrenheit temperature: "); double fahTemp = keyboard.nextDouble(); double celTemp = fahToCel(fahTemp); System.out.println(fahTemp + "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); } }