Java Program to Convert Fahrenheit to Celsius

In this program, we will learn how to convert Fahrenheit to Celsius using the Java Programming language. Let’s understand more about Fahrenheit, Celsius, and their conversion before directly jumping into the Java Program to convert Fahrenheit to Celsius. This will help us understand the logic better.

What is Fahrenheit to Celsius?

Fahrenheit to Celsius is a term used when we convert the given temperature from Fahrenheit to Celsius. These two are the most common scale to measure temperature in daily life.

What is Fahrenheit ?

Fahrenheit is a temperature scale according to which the freezing temperature of the water is 32 degrees and the boiling temperature of the water is 212 degrees. The symbol used to represent Fahrenheit is °F.

What is Celsius ?

Celsius is a temperature scale also known as Centigrades, according to which the freezing temperature of the water is 0 degrees and the boiling temperature of the water is 100 degrees. The symbol used to represent Celsius is °C.

Fahrenheit to Celsius Formula

The Fahrenheit to Celsius Formula which converts the value of °F to °C is as expressed as follows:

°C = (°F-32) * 5/9

Using the above formula we can convert the temperature given in Fahrenheit to Celsius. We are also going to use this formula to code the Java Program to convert Fahrenheit to Celsius.

Java Program to Convert Fahrenheit to Celsius

import java.util.*;

public class Main{
    
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the temperature in Farhenheit : ");
        float f = sc.nextFloat();
        
        // Converting Farhenheit to Celsius
        float c = (f-32)*5.0f/9.0f;
        
        System.out.println("The temperature is "+c+" degree Celsius.");
        
    }
    
}

Output 1

Enter the temperature in Fahrenheit: 98.60
The temperature is 37.0 degree Celsius.

Output 2

Enter the temperature in Fahrenheit: 212
The temperature is 100.0 degree Celsius.

Read more: Java Program to convert Celsius to Fahrenheit

How Does This Program Work ?

Scanner sc = new Scanner(System.in);
System.out.println("Enter the temperature in Farhenheit : ");
float f = sc.nextFloat();

In the above, we first took input from the user of temperature in Fahrenheit using Scanner class in Java and stored the value in the f variable of Float datatype as we are going to deal with decimal values. Hence, float datatype will be good for it.

// Converting Farhenheit to Celsius
        float c = (f-32)*5.0f/9.0f;

Then, we convert the given temperature in Fahrenheit to Celsius using the formula we discussed earlier and we stored the value in the c variable of float datatype.

System.out.println("The temperature is "+c+" degree Celsius.");

Finally, we displayed the conversion result. This is the Java Program to convert Fahrenheit into Celsius.

Conclusion

I hope after going through this post, you understand how to code Java Program to convert Fahrenheit into Celsius.
If you have any doubt regarding the topic, feel free to contact us in the Comment Section. We will be delighted to help you.

Also Read:

Leave a Comment

Your email address will not be published. Required fields are marked *