A knot is a unit of speed equal to one nautical mile per hou
A knot is a unit of speed equal to one nautical mile per hour. Write an application that displays every integer knot value from 15 through 30 and its kilometers per hour and miles per hour equivalents. One nautical mile is 1.852 kilometers or 1.151 miles. Save the file as Knots.java.
Solution
Hi, Please find my implementation.
PLease let me know in case of any issue.
public class Knots {
public static void main(String[] args) {
System.out.println(\"knot kilometers miles\");
for(int i=15; i<=30; i++){
// calculating equivalent kilometers and rounding in 3 decimal point
String kilo = String.format(\"%.3f\", (i*1.852));
// calculating equivalent miles and rounding in 3 decimal point
String miles = String.format(\"%.3f\", (i*1.151));
System.out.println(i+\" \"+kilo+\" \"+miles);
}
}
}
/*
Sample run:
knot kilometers miles
15 27.780 17.265
16 29.632 18.416
17 31.484 19.567
18 33.336 20.718
19 35.188 21.869
20 37.040 23.020
21 38.892 24.171
22 40.744 25.322
23 42.596 26.473
24 44.448 27.624
25 46.300 28.775
26 48.152 29.926
27 50.004 31.077
28 51.856 32.228
29 53.708 33.379
30 55.560 34.530
*/

