Java Arithmetic Operator calculate average speed in miles

Question

Assume a runner runs 14 kilometers in 45 minutes and 30 seconds.

We would like to write a program that displays the average speed in miles per hour.

1 mile is 1.6 kilometers.

Code structure you can use:

public class Main {
  public static void main(String[] args) {
    System.out.println();
  }
}


public class Main {
  public static void main(String[] args) {
    System.out.println((14 / 45.30) / 1.6);
  }
}

Note

To define method for the calculation:


public class Main {
  public static void main(String[] args) {
    System.out.println("mph: " + kphToMph(kilometersPerHour(14, 45.5)));
  }//from   w  w  w . ja  v a2s  .c om

  private static double kilometersPerHour(double kilometers, double minutes) {
    return 60.0 * (kilometers / minutes);
  }

  private static double kphToMph(double kph) {
    return kph / 1.6;
  }
}



PreviousNext

Related