Write TempConvert.java to output two temperature conversion tables.
The code:
// TempConvert.java
// F-to-C and C-to-F conversion tables;
// Uses two for loops
public class TempConvert {
public static void main(String[] args) {
// F-to-C table:
// Print table headings.
// The \t (tab) characters help to set consistent columns
// in the output.
System.out.println("Fahrenheit" + "\t\t\t" + "Celsius");
// Print table values using a for loop.
for ( int tempF = 0; tempF <= 212; tempF=tempF+2 ) {
double tempC = (tempF - 32) / 1.8;
System.out.println(tempF + "\t\t\t\t" + tempC);
} // end for
// Want an extra line between the tables
System.out.println();
// C-to-F table:
// Print table headings.
System.out.println("Celsius" + "\t\t\t\t" + "Fahrenheit");
// Print table values using a for loop.
for ( int tempC = 0; tempC <= 100; tempC=tempC+2 ) {
double tempF = (tempC * 1.8) + 32;
System.out.println(tempC + "\t\t\t\t" + tempF);
} // end for
} // end main
} // end class