Question: Write a program that displays a table of conversions from miles to kilometers for each integer mile ranging from 1 to 20. Note that 1
Write a program that displays a table of conversions from miles to kilometers for each integer mile ranging from 1 to 20. Note that 1 mile is 1.609344 kilometers.
Miles Kilometers ---------------- 1 1.6093 2 3.2187 3 4.8280 4 6.4374 5 8.0467 6 9.6561 7 11.2654 8 12.8748 9 14.4841 10 16.0934 11 17.7028 12 19.3121 13 20.9215 14 22.5308 15 24.1402 16 25.7495 17 27.3588 18 28.9682 19 30.5775 20 32.1869
The problem I get is 15 is sapposed to be 24.139 I get 24.140... it says it's wrong what can I do?
public class Lab8a {
public static void main(String[] args) {
final double KILOMETERS_PER_MILE = 1.6093;
System.out.println(
"Miles Kilometers");
for (int i = 1; i <= 20; i++) {
System.out.printf(
"%-13d%-10.3f ", i, (i * KILOMETERS_PER_MILE));
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
