运行时错误使用Scanner类

时间:2016-08-23 13:28:36

标签: java java.util.scanner

Error: Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Scanner.java:1540)
at Main.main(Main.java:13)

代码:

import java.util.Scanner;
public class Main
{
    public static void main (String[] args)
    {
        Scanner in;
        in = new Scanner(System.in); 
        String name;
        System.out.print("Enter your name: ");
        name = in.nextLine();
        System.out.print(name);    
    }
}

0 个答案:

没有答案