Advertisement
CR7CR7

SpeedConverter

Jun 24th, 2022
907
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.65 KB | None | 0 0
  1. public class SpeedConverter {
  2.  
  3.     public static long toMilesPerHour(double kilometersPerHour){
  4.  
  5.         if(kilometersPerHour < 0){
  6.  
  7.             return -1;
  8.  
  9.         }
  10.  
  11.             else {
  12.  
  13.             return Math.round(kilometersPerHour / 1.609);
  14.  
  15.             }
  16.  
  17.     }
  18.  
  19.  
  20.  
  21.     public static void printConversion(double kilometersPerHour) {
  22.  
  23.         int miles = (int) Math.round(kilometersPerHour / 1.609);
  24.  
  25.         if (kilometersPerHour < 0) {
  26.  
  27.             System.out.println("Invalid Value");
  28.  
  29.         } else {
  30.  
  31.             System.out.println(kilometersPerHour + " km/h " + "= " + miles + " mi/h");
  32.  
  33.         }
  34.  
  35.     }
  36.  
  37.    
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement