Assume a runner runs 24 miles in 1 hour, 40 ?minutes, and 35 seconds.
We would like to write a program that displays the average speed in kilometers per hour.
1 mile is 1.6 kilometers.
Code structure you can use:
public class Main { public static void main(String[] agrs) { //your code here } }
public class Main { public static void main(String[] agrs) { System.out.println("Miles / (hour + (minutes / 60) + (seconds / 3600)) * 1.6"); System.out.println("24 / (1 + (40 / 60) + (35 / 3600)) * 1.6"); System.out.println((24 / (1 + (40 / 60.0) + (35 / 3600.0))) * 1.6); } }
The following code creates method to clear the calculation steps.
public class Main { public static void main(String[] args) { System.out.println("kph: " + mphToKph(milesPerHour(24, 100.58))); }//from w ww . j a va2s . c om private static double milesPerHour(double miles, double minutes) { return 60.0 * (miles / minutes); } private static double mphToKph(double mph) { return mph * 1.6; } }