Write a program using Java that allows the user to convert a Celsius temperature
ID: 3662103 • Letter: W
Question
Write a program using Java that allows the user to convert a Celsius temperature to the Fahrenheit equivalent. Include a prompt for input and display the output when finished. The equation to be used for conversion can be seen here: Fahrenheit = (9 / 5) * Celsius + 32 For example, if you enter Celsius temperature 0, the degrees value in Fahrenheit is 32. Hint: Remember order of operations is important when evaluating expressions. Hint: Use double variables to store the temperature values rather than integer variables. Hint: The above equation is strictly mathematical. Part of the assignment is to transfer the equation into a Java expression. For instance, in Java, you must be sure to avoid the integer division that would be used if you put (9 / 5) in your expression as this would give wrong answers. Here is a sample run. Sample 1: Please input a Celsius temperature to be converted: 0 The corresponding temperature in Fahrenheit is 32.
JAVA
Explanation / Answer
// Celsius to Fahrenheit conversion in Java import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class CelsiusToFahrenheit { public static void main(String[] args) throws IOException{ BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Please enter temperature in Celsius : "); double celsius = Double.parseDouble(reader.readLine()); double fahrenheit = (9.0/5.0)*celsius + 32; System.out.println("Temperature in Fahrenheit is : "+fahrenheit); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.