Fahrenheit to Celsius degreeWrite a Java program to convert temperature from Fahrenheit to Celsius degree.The Fahrenheit scale is a temperature scale based on one proposed in 1724 by physicist Daniel Gabriel Fahrenheit. It uses the degree Fahrenheit (symbol: °F) as the unit.The Celsius scale, previously known as the centigrade scale, is a temperature scale used by the International System of Units (SI). As an SI derived unit, it is used by all countries in the world, except the U.S.Note:One inch is 0.0254 meter.Print upto 1 value after decimal Sample Input:Input a degree in FahrenheitSample Output:Output will have the Celsius degree value of the Fahrenheit degree input valueClick on the image for preview.Constraints:NAExample:Input:212Output:100.00Explanation:-Click on the image for preview.Public Test Cases:# INPUT EXPECTED OUTPUT1 212100.02 300148.9
Question
Fahrenheit to Celsius degreeWrite a Java program to convert temperature from Fahrenheit to Celsius degree.The Fahrenheit scale is a temperature scale based on one proposed in 1724 by physicist Daniel Gabriel Fahrenheit. It uses the degree Fahrenheit (symbol: °F) as the unit.The Celsius scale, previously known as the centigrade scale, is a temperature scale used by the International System of Units (SI). As an SI derived unit, it is used by all countries in the world, except the U.S.Note:One inch is 0.0254 meter.Print upto 1 value after decimal Sample Input:Input a degree in FahrenheitSample Output:Output will have the Celsius degree value of the Fahrenheit degree input valueClick on the image for preview.Constraints:NAExample:Input:212Output:100.00Explanation:-Click on the image for preview.Public Test Cases:# INPUT EXPECTED OUTPUT1 212100.02 300148.9
Solution
Here is a simple Java program that converts temperature from Fahrenheit to Celsius:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Input a degree in Fahrenheit: ");
double fahrenheit = scanner.nextDouble();
double celsius = (fahrenheit - 32) * 5/9;
System.out.printf("The Celsius degree value of the Fahrenheit degree input value is: %.2f", celsius);
}
}
This program works as follows:
-
It imports the Scanner class, which is used to get user input.
-
It creates a new instance of the Scanner class.
-
It prompts the user to enter a temperature in Fahrenheit.
-
It reads the user's input and stores it in the
fahrenheitvariable. -
It converts the temperature from Fahrenheit to Celsius using the formula
(fahrenheit - 32) * 5/9and stores the result in thecelsiusvariable. -
It prints the Celsius temperature, formatted to two decimal places.
Similar Questions
Which is the correct formula for converting degrees Celsius to degree Fahrenheit
Which temperature scale is used by scientists?*1 pointFahrenheitCelsiusKelvin
At what temperature are Celsius and Fahrenheit equal?
Create a Temprature class. Make two methods :1. convertFahrenheit - It will take celsius and will print it into Fahrenheit.2. convertCelsius - It will take Fahrenheit and will convert it into Celsius.
Describe the three temperature scales used in the laboratory and in everyday life: theFahrenheit scale, the Celsius scale, and the Kelvin scale
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.