中級 › NumberFormatException の原因と直し方 › パターン5
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: "42.0"exited with code 1
空欄を埋めてビルドを通す
parseIntは整数の文字列しか受け付けません。小数点が付いた時点で失敗します。
次の問題