3
我一直在試圖弄清楚如何使用Scanner
類一次輸入多個標記。我發現一些完美的代碼。我知道Scanner.hasNext
方法可以無限期阻止。爲什麼在這段代碼中的行keyboard = new Scanner(keyboard.nextLine());
阻止它這樣做?爲什麼線鍵盤=新掃描儀(keyboard.nextLine());保持程序掛起?
Scanner keyboard = new Scanner(System.in);
LinkedList<String> ll = new LinkedList<String>();
System.out.println("Please enter your full name: ");
keyboard = new Scanner(keyboard.nextLine());
while(keyboard.hasNext())
{
System.out.println("tag ");
ll.add(keyboard.next());
}
System.out.println(ll);
謝謝!