2016-12-28 25 views
1

我從控制檯讀取這種投入:與java.util.Scanner的Inifite環在Eclipse

word1 
word2 

word3 
word4 

我已經試過了:

public static void lectSC(Scanner sc, String l, boolean next) { 
     l=sc.nextLine();  //keep the first line 
     while(!l.isEmpty()){ //if it is not empty go! until the white line 
      checkDicc(l);//check if is the word that I am looking for 
      l=sc.nextLine(); //get the next word 
     } 
     l=sc.nextLine(); //take the nextLine which has a word3 
     while(!l.isEmpty()){ 
      parejas.add(l); 
      next=sc.hasNext(); //HERE IT IS THE INFINITY LOOP 
      if(next){ //I try with this next know which is the value of hasNext(), but I never arrive here when it is the last line. 
       l=sc.nextLine(); 
      }else{ 
       l=""; //It is how it should exit 
      } 
     } 
     System.out.println("OUT"); 
    } 

我不得不說,當我點擊我的鍵盤Ctrl-Z程序繼續,但它不能像那樣工作。

謝謝!

回答