Java program to enter the temperature in Fahrenheit and convert it to Celsius
ADVERTISEMENTS
Java program to enter the temperature in Fahrenheit and convert it to Celsius.
There are you will learn how to convert the temperature in Fahrenheit and convert it to Celsius in the Java language.
Formula:
C = (F - 32) * 5/9
Where:
F = fahrenheit
C = celsius
Let us understand this example through the Java program:
// Java program to convert the temperature from degree fahrenheit to celsius
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter the temperature in Fahrenheit::\n");
float f = in.nextFloat();
float c;
// c = celsius
// f = fahrenheit
/* Convert celsius to fahrenheit */
c = (float)((f - 32) * 5 / 9);
// Output
System.out.print("\n");
System.out.println(f + " Fahrenheit = " + c + " Celsius");
}
}
Output:
Enter the temperature in Fahrenheit::
7
7.0 Fahrenheit = -13.888889 Celsius