我已經正確設定了代碼沒有錯誤,但似乎是因為即使我輸入的整數高于程式的限制,它仍然會繼續到下一行 | 這是為了更好地理解的代碼:
do {
System.out.print("Enter the grade of the student for the subject " counter ": ");
grade = Integer.parseInt(kbd.nextLine());
if (grade < 65) {
System.out.println("Grades Range only from 65-99!");
}
if (grade > 99) {
System.out.println("Grades Range only from 65-99!");
}
} while (grade > 65 && grade < 99);
do {
System.out.print("Enter the number of units for the subject " counter ": ");
units = Integer.parseInt(kbd.nextLine());
if (units < 1) {
System.out.println("Units Range only from 1-12!");
}
if (units > 12) {
System.out.println("Units Range only from 1-12!");
}
} while (units > 1 && units < 12);
uj5u.com熱心網友回復:
你是說:當成績在 65 到 99 之間時回圈。只要閱讀你自己的代碼,如果這沒有幫助,請逐步完成,如果需要,使用筆和紙,并弄清楚你認為代碼應該做什么。然后,使用除錯器(或大量System.out.println 陳述句),并檢查計算機是否按照您的預期運行。
在你們兩個有分歧的地方,你發現了錯誤。
這個程序很容易發現這個錯誤。
現在你知道下次該做什么了。
uj5u.com熱心網友回復:
這是解決方案:
BEFORE: while (grade > 65 && grade < 99);
AFTER: while (grade < 65 || grade > 99);
BEFORE: (units > 1 && units < 12);
AFTER: (units < 1 || units > 12);
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/326941.html
