Java Program to Convert Celsius to Fahrenheit

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

What is Celsius to Fahrenheit?

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

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.

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.

Celsius to Fahrenheit Formula

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

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

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

Java Program to Convert Celsius to Fahrenheit

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 Celsius : ");
        float c = sc.nextFloat();
        
        // Converting Celsius to Fahrenheit
        float f = c * (9.0f/5.0f) + 32;
        
        System.out.println("The temperature is "+f+" degree Fahrenheit.");
        
    }
    
}

Output 1

Enter the temperature in Celsius : 37
The temperature is 98.6 degree Fahrenheit.

Output 2

Enter the temperature in Celsius : 100
The temperature is 212.0 degree Fahrenheit.

Read More: Java Program to convert Fahrenheit to Celsius

How Does This Program Work ?

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

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

        // Converting Celsius to Fahrenheit
        float f = c * (9.0f/5.0f) + 32;

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

 System.out.println("The temperature is "+f+" degree Fahrenheit.");

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

Conclusion

I hope after going through this post, you understand how to code Java Program to Convert Celsius to Fahrenheit.
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 *