The problem
In this exercise, write a program that displays the following table converting kilograms to pounds.
Breaking it down
Using an IntStream.rangeClosed
will create a range of numbers 1 to 200. Next calling Stream.forEach
will output table and conversion.
public static void main(String[] args) {
System.out.printf("%-12s%8s\n", "Kilograms", "Pounds");
IntStream.rangeClosed(1, 200).forEach(i -> {
System.out.printf("%-12d%8.1f\n", i, i * 2.2);
});
}
Output
Kilograms Pounds
1 2.2
2 4.4
3 6.6
4 8.8
5 11.0
6 13.2
7 15.4
8 17.6
9 19.8
10 22.0
...
190 418.0
191 420.2
192 422.4
193 424.6
194 426.8
195 429.0
196 431.2
197 433.4
198 435.6
199 437.8
200 440.0