5.4 (Conversion from miles to kilometers) Write a program that displays the following
table (note that 1 mile is 1.609 kilometers):
Miles Kilometers
1 1.609
2 3.218
...
9 14.481
10 16.090
Miles Kilometers
1 1.609
2 3.218
...
9 14.481
10 16.090
public class ProgrammingEx5_4 { public static void main(String[] args) { final int END = 10; // printing table header System.out.printf("%-9s%15s\n", "Miles", "Kilometers"); for (int i = 1; i <= END; i++) { System.out.printf("%-9d%15.1f\n", i, i * 1.609); } } }
No comments:
Post a Comment