g2401_2500.s2469_convert_the_temperature.Solution Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-java21 Show documentation
Show all versions of leetcode-in-java21 Show documentation
Java-based LeetCode algorithm problem solutions, regularly updated
package g2401_2500.s2469_convert_the_temperature;
// #Easy #Math #2023_01_11_Time_0_ms_(100.00%)_Space_40.6_MB_(87.87%)
/**
* 2469 - Convert the Temperature\.
*
* Easy
*
* You are given a non-negative floating point number rounded to two decimal places `celsius`, that denotes the **temperature in Celsius**.
*
* You should convert Celsius into **Kelvin** and **Fahrenheit** and return it as an array `ans = [kelvin, fahrenheit]`.
*
* Return _the array `ans`._ Answers within 10-5
of the actual answer will be accepted.
*
* **Note that:**
*
* * `Kelvin = Celsius + 273.15`
* * `Fahrenheit = Celsius * 1.80 + 32.00`
*
* **Example 1:**
*
* **Input:** celsius = 36.50
*
* **Output:** [309.65000,97.70000]
*
* **Explanation:** Temperature at 36.50 Celsius converted in Kelvin is 309.65 and converted in Fahrenheit is 97.70.
*
* **Example 2:**
*
* **Input:** celsius = 122.11
*
* **Output:** [395.26000,251.79800]
*
* **Explanation:** Temperature at 122.11 Celsius converted in Kelvin is 395.26 and converted in Fahrenheit is 251.798.
*
* **Constraints:**
*
* * `0 <= celsius <= 1000`
**/
public class Solution {
public double[] convertTemperature(double celsius) {
double kelvin = celsius + 273.15;
double fahrenheit = celsius * 1.80 + 32.00;
double[] arr = new double[2];
arr[0] = kelvin;
arr[1] = fahrenheit;
return arr;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy