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

gg0vcinb  于 2021-07-12  发布在  Java
关注(0)|答案(1)|浏览(393)
  1. import java.util.Scanner;
  2. public class Start {
  3. public static void main(String[] args) {
  4. Scanner sc = new Scanner(System.in);
  5. int b = 1;
  6. b = sc.nextInt();
  7. if (b == 1) {
  8. System.out.println("yes");
  9. } else {
  10. System.out.println("no");
  11. }
  12. int a = 2;
  13. a = sc.nextInt();
  14. if (a == 2) {
  15. System.out.println("yes");
  16. }
  17. }
  18. }

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

xmd2e60i

xmd2e60i1#

我更新了jdk,它成功了。在项目设置中,指定了javase-15,我将jdk从15更新为16,并在项目中指定了jdk16.0.1。

相关问题