Java program to convert fahrenheit to celsius

Views: 121   

Following program shows you how to convert fahrenheit to celsius.
In this program we get fahrenheit temperature from user and convert that fahrenheit temperature into celsius using following formula
Celsius = (fahrenheit - 32) * 5 / 9

import java.util.Scanner;

public class MathUnitConversions1 {

    public static void main(String[] args) {

        float temperature;

        Scanner in = new Scanner(System.in);

        System.out.println("Please enter temperature in fahrenheit:");
        temperature = in.nextFloat();

        float celsius = (temperature - 32) * 5 / 9;

        System.out.println("Temperature in celsius: " + celsius);

    }
}

Output:

Please enter temperature in fahrenheit:
77
Temperature in celsius: 25.0
On By