Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 扫描仪出错_Java - Fatal编程技术网

Java 扫描仪出错

Java 扫描仪出错,java,Java,下一行有问题,我不知道如何解决 System.out.println("Thats cool, I have thought that was a very interesting activity, how many hours a week do you do that."); String oftenHangOut = input.nextLine(); 要读取int,你应该这样做 int oftenHangOut = Integer.parseInt(oftenHangOut);

下一行有问题,我不知道如何解决

System.out.println("Thats cool, I have thought that was a very interesting activity, how   many hours a week do you do that.");
String oftenHangOut = input.nextLine();
要读取int,你应该这样做

int oftenHangOut = Integer.parseInt(oftenHangOut);

我在任何地方都看不到扫描仪对象;)但是,我认为,你想做这样的事情:

int oftenHangOut = input.nextInt();
或不进行分析:

    Scanner sc = new Scanner(System.in);
    System.out.println("Thats cool, I have thought that was a very interesting activity, how   many hours a week do you do that.");
    String oftenHangOut = sc.nextLine();
    int parsedInt = Integer.parseInt(oftenHangOut);
    if (parsedInt > 10) {
        System.out.println("Wow thats a lot you must love to do that.");
    } else {
        System.out.println("Cool, you must love to do that.");
    }

好的技巧是使用试抓拦网。您将看到出现了什么问题,以及应用程序停止的原因

首先,您可以解释它应该做什么,以及它应该做什么。integer不是类名,而是integer
    Scanner sc = new Scanner(System.in);
    System.out.println("Thats cool, I have thought that was a very interesting activity, how   many hours a week do you do that.");
    String oftenHangOut = sc.nextLine();
    int parsedInt = Integer.parseInt(oftenHangOut);
    if (parsedInt > 10) {
        System.out.println("Wow thats a lot you must love to do that.");
    } else {
        System.out.println("Cool, you must love to do that.");
    }
    Scanner sc = new Scanner(System.in);
    System.out.println("Thats cool, I have thought that was a very interesting activity, how   many hours a week do you do that.");
    int oftenHangOut = sc.nextInt();

    if (oftenHangOut > 10) {
        System.out.println("Wow thats a lot you must love to do that.");
    } else {
        System.out.println("Cool, you must love to do that.");
    }