Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我对 java 还很陌生,我想知道如何多次使用 Scanner.class
这意味着我希望程序允许我进行多个输入。
我知道对于 1 个输入,我可以使用:
Scanner scanner = new Scanner(System.in); String a = scanner.nextLine();
但是我该怎么做呢?
您可以重复使用相同的扫描仪对象:
Scanner scanner = new Scanner(System.in); String a = scanner.nextLine(); String b = scanner.nextLine(); // use the scanner object to get the next line