2012-12-09 73 views
-1
while (goodInput=false) 
     { 
      try 
      { 
       System.out.println("How long is the word you would like to guess?"); 
       wordSize=scan.nextInt(); 
       while(wordSize>word.longestWord()) 
       { 
        System.out.println("There are no words that big! Please enter another number"); 
        wordSize=scan.nextInt(); 
       } 
       goodInput=true; 
      } 
      catch(InputMismatchException ime) 
      { 
       System.out.println("Thats not a number! Try again"); 
      } 

     } 

我想提示用戶輸入號碼,但我不能讓它正確運行。我希望它保持運行,直到輸入正確的輸入。提示用戶,直到輸入正確的輸入類型

+0

目前會發生什麼? – OmniOwl

+1

「我無法讓它正常運行」是**不是一個真正的問題。 –

+0

非常感謝馬克。發生了什麼是它捕捉到錯誤,然後進入該段之後的下一行。我認爲南巴里所說的是什麼錯誤。 – jeanqueq

回答

2

的一個問題是:

while (goodInput=false) 

分配falsegoodInput成爲while(false)導致循環被不while循環在所有

改變它執行

while (!goodInput) 
+0

感謝您的幫助,我現在正在遞歸,但這可能是一個不同的問題。 – jeanqueq

+0

@aaronbobaron:我會首先建議調試(或)System.out,並查看哪些值導致遞歸。如果還存在問題,請發佈新問題。 – kosa

+0

再等27秒,再次感謝 – jeanqueq

0

條件需要成爲

while(goodinput == false) 

你在做什麼是分配false良好的輸入,導致最終結果爲false。請參閱以下語句的輸出,

boolean a; 
System.out.println((a = false)); 

您需要equality operator那裏。

0

首先,

while (goodInput=false) 

是指派falsegoodInput,你必須使用==操作tocheck如果goodInputfalse

while (goodInput==false) 

或者只是

while (!goodInput) would suffice 

這裏是重不辭而別到Equality Operator在Java

0

你必須寫

while (goodInput == false) 

甚至更​​好

while (!goodInput) 

,而不是

while (goodInput = false) 

的第一個goodInput值與false比較,第二個否定的值和您的版本分配falsegoodInput

相關問題