我是java新手,我的问题是......在学习java结束时我会发现有n更好的方法来做同样的事情?(我只是想加速学习过程)如果有人能给我一个更好的方法的例子,那么我可以理解我的代码。谢谢 !!
public static void main(String[] args) {
toMillesPerHour(50);
toMillesPerHour(90);
toMillesPerHour(100);
toMillesPerHour(130);
toMillesPerHour(-20);
}
public static void toMillesPerHour(double kilomettersPerHour) {
//return round value
if(kilomettersPerHour >= 0) {
kilomettersPerHour = (int) kilomettersPerHour / 1.60934;
int roundKm = (int) kilomettersPerHour;
System.out.println("You travel with speed of: " + roundKm +" Miles");
}else {
System.out.println("Negative value detected");
}
}
You travel with speed of: 31 Miles
You travel with speed of: 55 Miles
You travel with speed of: 62 Miles
You travel with speed of: 80 Miles
Negative value detected
一只甜甜圈
偶然的你
LEATH
慕妹3146593
相关分类