w3resource
Java Programming Exercies

Java Data Type Exercises: Fahrenheit to Celsius degree

Java Data Type: Exercise-1 with Solution

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

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

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?