Skip to content

Instantly share code, notes, and snippets.

@0ryant
Created August 1, 2019 09:38
Show Gist options
  • Save 0ryant/c48ce87a57e04c2462e45c78b183813a to your computer and use it in GitHub Desktop.
Save 0ryant/c48ce87a57e04c2462e45c78b183813a to your computer and use it in GitHub Desktop.
Java - Coding Challenge 1 - Speed Converter
public class SpeedConverter {
public static long toMilesPerHour(double kilometersPerHour){
if (kilometersPerHour <0) {
return -1;
}
return Math.round(kilometersPerHour/1.609);
}
public static void printConversion (double kilometersPerHour) {
if (kilometersPerHour <0) {
System.out.println("Invalid Value");
} else {
long mPH = toMilesPerHour(kilometersPerHour);
System.out.println(kilometersPerHour + " km/h = " + mPH + " mi/h");
}
}
}
@aiham-lab
Copy link

public class Main {
public static void main(String[] args) {

}

public static long toMilesPerHour(double kilometersPerHour) {
    if (kilometersPerHour < 0) {
        return -1;
    } else {
        return Math.round(kilometersPerHour / 1.609);
    }
}

public static void PrintConversion(double kilometersPerHour) {
    if (kilometersPerHour < 0) {
        System.out.println("print invalid value");
    } else {
        System.out.println(kilometersPerHour + "km/h   " + Math.round(kilometersPerHour / 1.609) + "mi/h ");
    }
}

}

@axelblaze0313
Copy link

yes first one is working now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment