为什么扫描仪会给出 java.util.InputMismatchException?

时间:2021-04-23 18:42:45

标签: java java.util.scanner

import java.util.Scanner;

public class Start {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int b = 1;
        b = sc.nextInt();
        if (b == 1) {
            System.out.println("yes");
        } else {
            System.out.println("no");
        }
        int a = 2;
        a = sc.nextInt();
        if (a == 2) {
            System.out.println("yes");
        }
    }
} 

如果我第二次输入一个整数,我会得到一个错误。 另一方面,在线JAVA编译器不会产生错误,这可能是技术错误? 如果是,如何解决。谢谢

1 个答案:

答案 0 :(得分:0)

我更新了 jdk 并且它起作用了。在项目设置中指定了JavaSE-15,我将jdk从15更新为16,并在项目中指定了jdk 16.0.1。