2017-04-03 53 views
-3

當我運行這個時,int x = 01被添加到x到它每次運行。該程序繼續打印出「第1輪」,不允許任何時間輸入任何內容。這不是關於閱讀輸入,而是關於如何輸入內容而不讓程序變得瘋狂。程序連續打印而不是等待輸入

while (!broken) { 

     int pointcount = 0; 

     System.out.println("Round " + x); 

     Scanner jumpOption = new Scanner(System.in); 

     if (jumpOption.equals("W")) { 

      pointcount += 1; 

      Random rand = new Random(); 

      if (rand.nextInt(100) == 0) { 
       broken = true; 

回答

0

你創建一個Scanner對象,但不使用它的任何實際閱讀。要獲得Scanner的任何輸入,您必須使用其中一種方法,如Scanner.nextLine()

Scanner myScanner = new Scanner(System.in); 
// Here's where we get the actual input! 
if (myScanner.nextLine().equals("Hello") 
+0

感謝您的幫助! –

0

你必須從掃描儀與next()方法

if (jumpOption.next().equals("W")) {