Loading...
Loading...
Loading...
A school weather club records temperatures in Celsius, but a visiting student wants them in Fahrenheit. Convert each reading with F = C × 9 / 5 + 32.
Write a method static double toFahrenheit(double celsius) that returns the Fahrenheit value. main reads the readings and prints each result with exactly one digit after the decimal point.
printf("%.1f%n", ...)).Example
Input
3 0 100 37
Output
32.0 212.0 98.6
Water freezes at 32.0 °F and boils at 212.0 °F; 37 °C is 98.6 °F.
Try the problem first. Open one hint at a time.
Write the formula with decimals, celsius * 9.0 / 5.0 + 32, so Java does not do integer division.
An int argument can be passed to a double parameter; Java widens it for you.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor