Integer型以外が入力されたときにNumberFormatExceptionが表示されるようにしたいのですが現状ではInputMismatchExceptionが出てしまいます
java
1public class Main { 2 public static void main(String[] args) { 3 4 try { 5 Integer number; 6 number = new java.util.Scanner(System.in).nextInt(); 7 8 } catch (NumberFormatException e) { 9 System.out.println("java.lang.NumberFormatException:"); 10 11 } catch (InputMismatchException e) { 12 System.out.println("java.langl.InputMismatchException:"); 13 } 14 15 } 16}
実装されているものをあなたの事情で受け取るものを変えたいのであればラッパークラスでそういう実装にしてください
回答2件
あなたの回答
tips
プレビュー