Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /**
- A program that reads in a temperature in degrees Fahenheit
- and converts it to the equivalent temperature in Celsius
- and also the equivalent temperature in Kelvin.
- For example, if the input is F = 68.0 degrees Fahrenheit,
- then the conversions should show that C = 20.0 degrees Celsius
- and K = 293.0 degrees Kelvin.
- */
- public class ConvertTemp
- {
- public static void main (String[] args)
- {
- // Define constants
- double farenheitToCelsius = 5.0d/9.0d;
- double celciusToKelvin = 273.0d;
- // Display prompt for temperature in degrees Farhenheit
- System.out.print("Please enter the temperature ");
- System.out.println("in degrees Farhenheit: ");
- // Read Fahrenheit temperature
- Scanner in = new Scanner(System.in);
- double fahrenheit = in.nextDouble();
- // Compute Celsius and Kelvin equivalents
- double celsius = (fahrenheit - 32.0d) * farenheitToCelsius;
- double kelvin = celsius + celciusToKelvin;
- // Print out equivalents
- System.out.println(celsius);
- System.out.println(kelvin);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement