Files

Inches to centimeters

The program below prints a table that converts inches to centimeters.

1
2
3
4
5
6
7
8
9
10
11
//Print table of inches to CM
package somePackage;
import java.util.*;
public class InchesTable {
	public static void main(String[] args) {
		System.out.println("Inches   CM");
		for(int inches=1; inches<20; inches++) {
			System.out.println(String.format("%2d     %.2f",inches, inches*2.54));
		}//for
	}//main
}//class
CODE

The output appears as shown below:

Inches   CM
 1     2.54
 2     5.08
 3     7.62
 4     10.16
 5     12.70
 6     15.24
 7     17.78
 8     20.32
 9     22.86
10     25.40
11     27.94
12     30.48
13     33.02
14     35.56
15     38.10
16     40.64
17     43.18
18     45.72
19     48.26

We could copy and paste it to a file if we wanted.

Instead the next program writes the output to a file.

NEXT: