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);
谢谢!