forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemperatureConverter.java
More file actions
46 lines (38 loc) · 1.26 KB
/
TemperatureConverter.java
File metadata and controls
46 lines (38 loc) · 1.26 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.thealgorithms.conversions;
/**
* A utility class to convert between different temperature units.
*
* <p>This class supports conversions between the following units:
* <ul>
* <li>Celsius</li>
* <li>Fahrenheit</li>
* <li>Kelvin</li>
* </ul>
*
* <p>This class is final and cannot be instantiated.
*
* @author krishna-medapati (https://github.com/krishna-medapati)
* @see <a href="https://en.wikipedia.org/wiki/Conversion_of_scales_of_temperature">Wikipedia: Temperature Conversion</a>
*/
public final class TemperatureConverter {
private TemperatureConverter() {
}
public static double celsiusToFahrenheit(double celsius) {
return celsius * 9.0 / 5.0 + 32.0;
}
public static double celsiusToKelvin(double celsius) {
return celsius + 273.15;
}
public static double fahrenheitToCelsius(double fahrenheit) {
return (fahrenheit - 32.0) * 5.0 / 9.0;
}
public static double fahrenheitToKelvin(double fahrenheit) {
return (fahrenheit - 32.0) * 5.0 / 9.0 + 273.15;
}
public static double kelvinToCelsius(double kelvin) {
return kelvin - 273.15;
}
public static double kelvinToFahrenheit(double kelvin) {
return (kelvin - 273.15) * 9.0 / 5.0 + 32.0;
}
}