Write a program called Fahrenheit2Celsius that converts a temperature in Fahrenh
ID: 3748708 • Letter: W
Question
Write a program called Fahrenheit2Celsius that converts a temperature in Fahrenheit to Celcius.Your program must declare two double variables named fahrenheit and celcius and one Scaner variable named input. Declare variables in the order listed. Declare fahrenheit and celcius on the same line and initialize to 0.0. The program will prompt the user for temperature in Fahrenheit and read the input from the keyboard storing the value in in the fahrenheit variable. The Celsius temperature is calculated by (fahrenheit - 32) times 5/9. The result is stored in the variable celcius. The required output is provided. The "Yes" is not used.
OUTPUT:
Enter a temperature in degrees Fahrenheit to convert : 50
50.0 degrees Fahrenheit converts to 10.0 degrees Celcius.
Explanation / Answer
import java.util.*;
class Fahrenheit2Celsius
{
public static void main (String[] args)
{
double fahrenheit=0.0, celcius= 0.0;
Scanner input = new Scanner(System.in);
System.out.println("Enter a temperature in degrees Fahrenheit to convert : ");
fahrenheit = input.nextDouble();
celcius = (fahrenheit - 32.0) * 5.0/9.0;
System.out.printf("%.1f degrees Fahrenheit converts to %.1f degrees Celcius.",fahrenheit,celcius);
}
}
Output:
Enter a temperature in degrees Fahrenheit to convert :50
50.0 degrees Fahrenheit converts to 10.0 degrees Celcius.
Do ask if any doubt. Please upvote.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.