Advertisement
advictoriam

Untitled

Nov 28th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /**
  4.    A program that reads in a temperature in degrees Fahenheit
  5.       and converts it to the equivalent temperature in Celsius
  6.       and also the equivalent temperature in Kelvin.
  7.    For example, if the input is F = 68.0 degrees Fahrenheit,
  8.       then the conversions should show that C = 20.0 degrees Celsius
  9.       and K = 293.0 degrees Kelvin.
  10. */
  11. public class ConvertTemp
  12. {
  13.    public static void main (String[] args)
  14.    {
  15.       // Define constants
  16.       double farenheitToCelsius = 5.0d/9.0d;
  17.       double celciusToKelvin = 273.0d;
  18.  
  19.       // Display prompt for temperature in degrees Farhenheit
  20.       System.out.print("Please enter the temperature ");
  21.       System.out.println("in degrees Farhenheit: ");
  22.  
  23.       // Read Fahrenheit temperature
  24.       Scanner in = new Scanner(System.in);
  25.       double fahrenheit = in.nextDouble();
  26.  
  27.       // Compute Celsius and Kelvin equivalents
  28.       double celsius = (fahrenheit - 32.0d) * farenheitToCelsius;
  29.       double kelvin = celsius + celciusToKelvin;
  30.  
  31.       // Print out equivalents
  32.       System.out.println(celsius);
  33.       System.out.println(kelvin);
  34.    }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement