Code Fix

中級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

空欄を埋めてビルドを通す

広告
広告スロット(未設定)

NumberFormatException の原因と直し方

空白や記号が混ざる入力の扱い方を解説します。

このエラーの解説と類題をまとめて見る →

広告
広告スロット(未設定)