2016-02-11 26 views
-1
import java.lang.Math; 

public class LogicTableGenerator 

{ 

    public static void main(String[] args) 

    { 
     double numletters; 
     System.out.println("how many letters exist in your logic table?"); 
     numletters=TextIO.getInt(); double totalpremises; 
     totalpremises=Math.pow(2.0,numletters); 
     System.out.println("what letters are you using?"); 
     char letter; letter = 'A'; char letter1, letter2, letter3, letter4,letter5,letter6,letter7,letter8,letter9; 
     int numstop; numstop =0; 
     System.out.println(numstop); 
     boolean bag; 
     bag=(1!=1); 
     System.out.println(bag); 

     while (!(numstop == 1)) 
     { 
      letter1=TextIO.getChar(); 
      System.out.println("Do you awant to stop? Press 1 for Yes, otherwise press a different number."); 
      numstop=TextIO.getInt(); 
      System.out.println(numstop); 
      letter2=TextIO.getChar(); 
      System.out.println(numstop); 
      System.out.println("Do you want to stop? Press 1 for Yes, otherwise press a different number."); 
      numstop=TextIO.getInt(); 
      letter3=TextIO.getChar(); 
      System.out.println("Do you want to stop? Press 1 for Yes, otherwise press a different number."); 
      numstop=TextIO.getInt(); 
      letter4=TextIO.getChar(); 
      System.out.println("Do you want to stop? Press 1 for Yes, otherwise press a different number."); 
      numstop=TextIO.getInt(); 
      letter5=TextIO.getChar(); 
      System.out.println("Do you want to stop? Press 1 for Yes, otherwise press a different number."); 
      numstop=TextIO.getInt(); 
      letter6=TextIO.getChar(); 
      System.out.println("Do you want to stop? Press 1 for Yes, otherwise press a different number."); 
      numstop=TextIO.getInt(); 
      letter7=TextIO.getChar(); 
      System.out.println("Do you want to stop? Press 1 for Yes, otherwise press a different number."); 
      numstop=TextIO.getInt(); 
      letter8=TextIO.getChar(); 
      System.out.println("Do you want to stop? Press 1 for Yes, otherwise press a different number."); 
      numstop=TextIO.getInt(); 
      letter9=TextIO.getChar(); 
      System.out.println("You have reached the end of the road. You are now done."); 

     } 


    } 

} 

我不理解這是爲什麼不停止,一旦numstop等於1不應循環結束匹配?While循環不會在Java終止即使數值情況下,布爾值

堆棧溢出是讓我發佈更多細節,實在是沒有什麼後請不要讀這個,因爲它只是包含了一堆話,如果你還在讀書,請現在停止閱讀

+1

請閱讀[問]並嘗試製作[mcve]。你的問題缺少一個明確的問題陳述。此外,請格式化您的代碼... – Tunaki

+1

什麼是'TextIO'? – brso05

+0

根據代碼循環將繼續運行,直到numstop不變爲1.您的while可以被重寫爲while(numstop!= 1)。你確定你正在碰到這種情況嗎? – user3509208

回答

1

環路會持續到循環結束,此時它將檢查while循環是否仍然有效。本質上,它將執行while循環內的所有內容,不管怎樣,都不會停下來重新考慮while循環條件是否仍然有效,直到達到結尾爲止,然後循環回去。

1

目前還不清楚你的代碼的目標是什麼,但是如果你想打破所有展開的事情,你將需要檢查導致循環在每次輸入數字後退出的情況,然後手動打破循環。雖然我很困惑,爲什麼你不會將每個字符追加到一個字符串,然後循環直到遇到停止令牌,然後手動中斷。

0

如果你想保持這種編碼風格,那麼只需在閱讀下一封信之前添加一張支票。例如,

  letter1=TextIO.getChar(); 
      System.out.println("Do you awant to stop? Press 1 for Yes, otherwise press a different number."); 
      numstop=TextIO.getInt(); 
      System.out.println(numstop); 
      if (numstop==1) break; 
      letter2=TextIO.getChar(); 
      ... 
相關問題