Celsius to Fahrenheit
Programming Basics · Java
TASK
Problem
Given temperature in Celsius, print Fahrenheit using `F = C * 9 / 5 + 32`.
EXAMPLE
Example
25
77.0
LIMITS
Constraints
-1000 ≤ C ≤ 1000
LEARN
Theory for this problem
+
The core idea of **Celsius to Fahrenheit** is to model the requested operation directly: Given temperature in Celsius, print Fahrenheit using `F = C * 9 / 5 + 32`. The reference solution uses `Scanner` for input. Keep only the state needed for this result, choose numeric types that cover the stated bounds, and preserve the exact input/output contract. This makes the solution easier to verify on boundary cases and avoids unrelated work.
NEED HELP?
Hints
+
['Follow the statement for **Celsius to Fahrenheit** literally and identify the smallest state needed to produce its output.', 'The reference solution relies on `Scanner` for input; test the smallest allowed input and one boundary case from the constraints.']
ANSWER
Solution
+
// CodeMaster — Celsius to Fahrenheit
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
double c = sc.nextDouble();
double f = c * 9.0 / 5.0 + 32.0;
System.out.println(f);
}
}