HomePOSTProgram to Convert Fahrenheit to Celsius in Java Language (updated)

Program to Convert Fahrenheit to Celsius in Java Language (updated)

Java program to convert the temperature from Celsius to Fahrenheit. In a similar way, we can also write Java program to convert the temperature from Fahrenheit to Celsius.

The formula that will be used for this problem is,

⁰C = ( 5 / 9 ) * ( ⁰F – 32 )

<img width=

Convert Fahrenheit to Celsius in Java Language (updated)

import java.util.Scanner;

public class TemperatureConversion {

  // method to convert fahrenheit to celsius
  public static double toCelsius(double fahrenheit){
     return ((5.0/9.0) * (fahrenheit - 32));
  }

  public static void main(String[] args) {

     // declare variables
     double celsius = 0.0;
     double fahrenheit = 0.0;

     // create Scanner class object
     Scanner scan = new Scanner(System.in);

     // read input
     System.out.print("Enter Fahrenheit value::");
     fahrenheit = scan.nextDouble();

     // convert temperature
     celsius = toCelsius(fahrenheit);

     // display result
     System.out.format("Celsius value = %.2f",
                          celsius);

     // close Scanner class object
     scan.close();
  }
}

OUTPUT



Enter Fahrenheit value:: 98
Celsius value = 36.67

Types of Sorting Algorithms:

Additional Reading

READ MORE

If you found this post useful, don’t forget to share this with your friends, and if you have any query feel free to comment it in the comment section.

Thank you 😊 Keep Learning !

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -

Most Popular

- Advertisment -