Convert Fahrenheit to Celsius back and forth with float in Java
Description
The following code shows how to convert Fahrenheit to Celsius back and forth with float.
Example
/*from w w w. j a v a 2s. c om*/
public class Main {
public static void main(String[] arguments) {
float fah = 86;
System.out.println(fah + " degrees Fahrenheit is ...");
fah = fah - 32;
fah = fah / 9;
fah = fah * 5;
System.out.println(fah + " degrees Celsius\n");
float cel = 33;
System.out.println(cel + " degrees Celsius is ...");
cel = cel * 9;
cel = cel / 5;
cel = cel + 32;
System.out.println(cel + " degrees Fahrenheit");
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »