-5
我在這裏寫了這段代碼。它應該打印出由用戶輸入確定的iteNum.length
(數組),但它只執行一次迭代,然後停止。我無法弄清楚爲什麼。我的循環只經過一次
for (int i = 0; i < iteNum.length; i++) {
System.out.print("Num:" + (i+1) + " ");
for (i = 0; i < cMiles.length; i++) {
System.out.print(" (sc" + (i+1) + ":)" + cRandom[i] + " (tsc" + (i+1) + ":)" + df.format(cTimes[i]) + " ");
}
for (i = 0; i < fMiles.length; i++){
System.out.print(" (sf"+ (i+1) + ":)" + df.format(fRandom[i]) + " (tsf" + (i+1) + ":)" + df.format(fTimes[i])+ " ");
}
System.out.print("(cT:)" + df.format(cSum) + " (fT:)" + df.format(fSum));
if (cSum < fSum) {
System.out.print(" City is faster");
}
else {
System.out.print(" Freeway is faster");
}
}
不幸的是這樣做更有意義,但我們的老師希望我們對這部分使用if else語句。 –