我有一個小麻煩抓的區別! ||當他們在一段時間的條件下進行測試時,它們將被編號爲& &。在下面的例子中,我希望程序提出一個問題:「你看到屏幕上有四個?」那麼如果這個人沒有答案,那麼這個計劃會繼續下去,並繼續問。如果用戶輸入答案「是」,則程序退出但我的程序不存在。
在我while循環的條件我要告訴while循環繼續只要我都小於5,問題的答案是肯定的不是?如何正確的思考方式! ||和& &在while循環的上下文中使用?測試真/假的條件使用! ||和&&運營商
import acm.program.*;
public class WhileConditionTestProgram extends ConsoleProgram{
public void run(){
String question = ("do you see a four on the screen? ");
int i = 1;
while(i <= 20 && !(question.equals("yes"))){
String question = readLine("do you see a 4 on the screen?: ");
i++;
}
}
}
請仔細觀察while循環內的變量名稱以及您在條件中使用的變量名稱。 –
你永遠不會更新'答案',所以它永遠不會等於'「是」'。 – rgettman
'字符串問題=的readLine(「你看到一個4在屏幕上?:」);' –