w3resource

Java: Fahrenheit to Celsius degree


Convert Fahrenheit to Celsius

Write a Java program to convert temperature from Fahrenheit to Celsius degrees.

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.

Test Data
Input a degree in Fahrenheit: 212


Java datatype Exercises: Fahrenheit to Celsius degree

Sample Solution:

Java Code:

import java.util.Scanner;
public class Exercise1 {

    public static void main(String[] Strings) {

        Scanner input = new Scanner(System.in);

        System.out.print("Input a degree in Fahrenheit: ");
        double fahrenheit = input.nextDouble();

        double  celsius =(( 5 *(fahrenheit - 32.0)) / 9.0);
        System.out.println(fahrenheit + " degree Fahrenheit is equal to " + celsius + " in Celsius");
    }
}

Sample Output:

Input a degree in Fahrenheit: 212                                                                             
212.0 degree Fahrenheit is equal to 100.0 in Celsius 

Flowchart:

Flowchart: Java Data Type Exercises - Fahrenheit to Celsius degree

For more Practice: Solve these Related Problems:

  • Write a Java program to convert a series of Fahrenheit values (read from a file) to Celsius and then compute the minimum, maximum, and average Celsius temperatures.
  • Write a Java program to implement the Fahrenheit to Celsius conversion using Java 8 streams and lambda expressions to process a list of temperature inputs.
  • Write a Java program to convert Fahrenheit to Celsius while handling extreme values and potential input errors with robust exception handling.
  • Write a Java program to build a simple GUI that converts user-entered Fahrenheit values to Celsius in real time and displays the result dynamically.

Java Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Data Types Exercises
Next: Write a Java program that reads a number in inches, converts it to meters.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.