How to Convert Fahrenheit to Celsius in Java
Convert Fahrenheit to Celsius
To Convert Fahrenheit to Celsius:
- Take the temperature in Fahrenheit subtract 32.
- Divide by 1.8.
- The result is degrees Celsius.
public class Main {
//from w w w .ja v a2s .c om
public static void main(String[] args) {
for (int i=-40; i<=120; i+=10) {
float c = (i-32)*(5f/9);
System.out.println("fahrenheit "+i + " to celsius " + c);
}
}
}
The code above generates the following result.
To Convert Celsius to Fahrenheit
- Take the temperature in Celsius and multiply 1.8.
- Add 32 degrees.
- The result is degrees Fahrenheit.