Open In App

Java Program to Convert Fahrenheit into Celsius

Last Updated : 12 Sep, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Here we are converting Fahrenheit temperature value to Celsius temperature value. Fahrenheit and Celsius are the measures of temperature having Unit in degrees as oF and oC respectively.

Formula

Celsius = (Fahrenheit - 32) / 1.8

Approach

  1. Initialize the  value of Fahrenheit as 50.0 and Celsius as 0.0
  2. Calculate the Celsius using the above given formula.
  3. Display Celsius temperature.

Example

Java




// Java Program to Convert Fahrenheit into Celsius
 
class fahrenheittocelsius {
   
    public static void main(String[] args)
    {
        // temperature in fahrenheit
        double fahrenheit = 50.0, celsius = 0.0;
 
        // calculate celsius temperature
        celsius = (fahrenheit - 32) / 1.8;
 
        // print the celsius temperature
        System.out.println(
            "value of temperature in celsius:" + celsius);
    }
}


Output

value of temperature in celsius:10.0

Time Complexity: O(1)

Auxiliary Space: O(1) as it is using constant variables


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads