InputMismatchException cannot be resolved to a type
try{ System.out.println("輸入第一個(gè)數(shù)"); Scanner?input?=?new?Scanner(System.in); int?firstNum?=?input.nextInt(); System.out.println("輸入第二個(gè)數(shù)"); int?secondNum?=?input.nextInt(); int?result?=?firstNum/secondNum; System.out.println("兩數(shù)之商為"?+?result); }?catch?(ArithmeticException?e)?{ System.out.println("除數(shù)為0"); }?catch?(InputMismatchException?e){ System.out.println("需要輸入整數(shù)"); }?catch?(Exception?e){ System.out.println("不知名錯(cuò)誤"); }
剛開(kāi)始提示“InputMismatchException cannot be resolved to a type”,后來(lái)在前面import 了 java.util.InputMismatchException之后就OK了,但是AritheticException 這個(gè)異常就不需要import什么類(lèi)啊,不明白是怎么回事~~求指導(dǎo)?
? java.lang.RuntimeException
? ? ? ? ? ? ?java.util.NoSuchElementException
? ? ? ? ? ? ? ? ?java.util.InputMismatchException
java.lang.RuntimeException
? ? ? ? ? ? ?java.lang.ArithmeticException
2016-05-25
在前面加入import java.util.*;就可以了
2015-12-15
因?yàn)锳rithmeticException這個(gè)類(lèi)是存在于java.lang這個(gè)包的,默認(rèn)情況下這個(gè)包中的所有類(lèi)會(huì)被自動(dòng)導(dǎo)入所有的程序。而InputMismatchException是java.util的包,需要手動(dòng)導(dǎo)入