public class Shuffle1 {
public static void main(String[] args) {
int x = 3;
if(x > 2) {
System.out.print("a");
}
while(x > 0) {
x = x - 1;
System.out.print("-");
}
if(x == 2) {
System.out.print("b c");
}
if(x == 1) {
System.out.print("d");
x = x - 1;
}
}
}
我正在學習一本名爲「Head First Java」的書中的Java,並且我正按照本書中的建議使用TextEdit。我應該能夠編譯代碼以獲得a-b c-d的答案,但是每次編譯它時,我都會得到一個---的結果。我已經徹底檢查過自己,如果有人能幫助我,我會很感激。 Here is the original question from the book.循環和如果語句不給所需的輸出
我認爲第二個和第三個if語句應該放在while循環中。 – markspace
這是在調試器中單步執行代碼的地方,可以真正幫助您調試程序。它還將幫助您通過練習來逐步完成頭腦中的代碼。 –