Java Program to Convert Fahrenheit to Centigrade

Java program to convert fahrenheit to centigrade can be implemented by using following formula


$C = \frac{(F-32)*5}{9}$


Here, value of $F$ is the temperature in fahrenheit while $C$ is the temperature in centigrade.

Fahrenheit and Centigrade are two well known temperature scales. Both of them are used regularly in daily temperature measurements. By using above formula, the following Java program produces output in celcius ($^{\circ}C$) while taking fahrenheit ($^{\circ}F$) as input.






1. Java Program & output to convert fahrenheit to centigrade

Code has been copied
/************************************************
             alphabetacoder.com
 Java program to convert Fahrenheit to Centigrade
*************************************************/

import java.util.Scanner;
public class Main {
    public static void main(String args[]) {

        double f, c;
        // declare an instance of Scanner class
        Scanner sc = new Scanner(System.in);
        //take input in fahrenheit
        System.out.print("Enter the temperature in fahrenheit = ");
        f = sc.nextDouble();

        //convert fahrenheit and c
        c = 5 * (f - 32) / 9;

        System.out.print("Temperature is " + c + " in centigrade When " + f + " in fahrenheit.");
    }
}

Output


Enter the temperature in fahrenheit = 212

Temperature is 100.0 in centigrade When 212.0 in fahrenheit.