中級 › NumberFormatException の原因と直し方 › パターン1
NumberFormatException の原因と直し方
parseIntは全体が数値でなければ失敗します。
1 public class Main { 2 public static void main(String[] args) { 3 String s = ______; ^ 4 System.out.println(Integer.parseInt(s)); 5 } 6 }
Exception in thread "main" java.lang.NumberFormatException: For input string: "12a"exited with code 1
空欄を埋めてビルドを通す
parseIntは全体が数値でなければ例外を投げます。前後の空白も許容されません。
次の問題