InputMismatchException cannot be resolved to a type

来源:1-2 Java中使用try..catch..finally实现异常处理

慕雪7762075

2015-08-06 16:12

try{
			System.out.println("输入第一个数");
			Scanner input = new Scanner(System.in);
			int firstNum = input.nextInt();
			System.out.println("输入第二个数");
			int secondNum = input.nextInt();
			int result = firstNum/secondNum;
			System.out.println("两数之商为" + result);
		} catch (ArithmeticException e) {
			System.out.println("除数为0");
		} catch (InputMismatchException e){
			System.out.println("需要输入整数");
		} catch (Exception e){
			System.out.println("不知名错误");
		}

刚开始提示“InputMismatchException cannot be resolved to a type”,后来在前面import 了 java.util.InputMismatchException之后就OK了,但是AritheticException 这个异常就不需要import什么类啊,不明白是怎么回事~~求指导 


  java.lang.RuntimeException
             java.util.NoSuchElementException
                 java.util.InputMismatchException

java.lang.RuntimeException

             java.lang.ArithmeticException

写回答 关注

1回答

  • stt54321
    2015-12-15 14:37:31

    因为ArithmeticException这个类是存在于java.lang这个包的,默认情况下这个包中的所有类会被自动导入所有的程序。而InputMismatchException是java.util的包,需要手动导入

Java入门第三季

Java中你必须懂得常用技能,不容错过的精彩,快来加入吧

409784 学习 · 4339 问题

查看课程

相似问题