0
爲什麼我需要進口InputMismatchException時,當我嘗試try/catch語句和InputMismatchException時
catch(InputMismatchException e){
System.out.println("cant print");
,但是當我嘗試以下方法,我沒有導入什麼?
catch(ArithmeticException e){
System.out.println("cant print");
由於類InputMismatchException時最初不導入而AirthmeticException是。同樣的原因,爲什麼你可以在沒有導入的情況下使用'System.out.println'而不是'Math.sqrt'。 – ctst
算術異常來自java.lang包,它是不需要導入的默認包。 InputMismatchexception來自java.util包 – Shriram