Speed-Converter
Code to convert kilometers to Miles-PerHour:
Program
public class SpeedConverter {
public static void main(String[] args) {
}
public long toMilesPerHour(double kiloMeterPerHour) {
if (kiloMeterPerHour < 0)
return -1;
long milesPerHour = Math.round(kiloMeterPerHour / 1.609);// convert kilometers to miles
return milesPerHour;
}
}
Optimize code:
public class SpeedConverter {
public static void main(String[] args) {
}
public long toMilesPerHour(double kiloMeterPerHour) {
if (kiloMeterPerHour < 0)
return -1;
return Math.round(kiloMeterPerHour / 1.609);// convert kilometers to miles
}
}
Code to convert kilometers to Miles-PerHour:
Program
public class SpeedConverter {
public static void main(String[] args) {
}
public long toMilesPerHour(double kiloMeterPerHour) {
if (kiloMeterPerHour < 0)
return -1;
long milesPerHour = Math.round(kiloMeterPerHour / 1.609);// convert kilometers to miles
return milesPerHour;
}
}
Optimize code:
public class SpeedConverter {
public static void main(String[] args) {
}
public long toMilesPerHour(double kiloMeterPerHour) {
if (kiloMeterPerHour < 0)
return -1;
return Math.round(kiloMeterPerHour / 1.609);// convert kilometers to miles
}
}
No comments:
Post a Comment