- import java.util.Scanner;
- public class ScannerQues
- {
- /**
- * 两个方法中都调用了Scanner的nextLine()方法,
- * 当输入了第一个后,为什么会报错:java.util.NoSuchElementException?
- *
- */
- public static void main(String[] args)
- {
- register();
- login();
- }
-
- public static void register()
- {
- Scanner can = new Scanner(System.in);
- System.out.print("register 输入:");
- String str = can.nextLine();
- System.out.println(str);
- can.close();
- }
-
- public static void login()
- {
- Scanner can = new Scanner(System.in);
- System.out.print("login 输入:");
- String str = can.nextLine();
- System.out.println(str);
- can.close();
- }
- }
复制代码 |