Monday, June 26, 2006

Temperature Conversion

Program

package bloggingjava;

import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        // temperature conversion
        BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("deg F\t\tdeg C");
        for(; ; ) {
            System.out.println("Enter deg F");
            double F = Double.parseDouble(stdin.readLine());
            System.out.println(F + "\t\t" + (F - 32) / 1.8);
            // no break statement
        }
    }
}

Output

deg F           deg C
Enter deg F
32
32.0            0.0
Enter deg F
50
50.0            10.0
Enter deg F
68
68.0            20.0
Enter deg F
Ctrl+C  

References

No comments: