Fahrenheit To Celsius Example Java Program


Formula

[C] = ([F] - 32) * 5?9

where,
[F] is the temperature in Fahrenheit scale
[C] is the temperature in Celsius scale

Fahrenheit To Celsius Example Program

import java.util.Scanner;

public class FahrenheitToCelsius {
    public static void main(String[] args) {
		System.out.println("Enter a temperature in Fahrenheit: ");
		Scanner in = new Scanner(System.in);
		double Celsius = 0;
		if(in.hasNextDouble()){
			Celsius = (in.nextDouble() - 32)*5/9;
        }
        System.out.println("The temperature in Celsius is: "+Celsius);
    }
 
}

Sample Output

Output is:
Enter a temperature in Fahrenheit:
183
The temperature in Celsius is: 83.88888888888889