-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtempConversion_2.java
More file actions
28 lines (23 loc) · 850 Bytes
/
tempConversion_2.java
File metadata and controls
28 lines (23 loc) · 850 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.util.Scanner;
public class tempConversion_2 {
public static void main(String[] args) {
// Instantiating scanner
Scanner scnr = new Scanner(System.in);
// Declaring variables
double tempInKelvin;
double tempInFahrenheit;
double degreeDifferenceCToK = 273.15;
double degreeDifferenceCToF = 32;
double degreeRatio = (9.0/5.0);
// Collecting user input
System.out.print("Enter temperature in Kelvin : ");
tempInKelvin = scnr.nextDouble();
// Calculating
tempInFahrenheit = (tempInKelvin - degreeDifferenceCToK) * degreeRatio + degreeDifferenceCToF;
// Printing outputs
System.out.printf("%.2f", tempInKelvin);
System.out.print(" degrees Kelvin is ");
System.out.printf("%.2f", tempInFahrenheit);
System.out.println(" degrees Fahrenheit");
}
}