Java 中的數字格式化異常是什麼?
當您將一個錯誤格式的字串變數轉換為一個不相容的整數(數字格式)時,就會發生此異常。
示例
public class Test { public static void main(String[] args) { int data = Integer.parseInt("hello"); } }
輸出
Exception in thread "main" java.lang.NumberFormatException: For input string: "hello" at java.lang.NumberFormatException.forInputString(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at a6.dateAndTime.Test.main(Test.java:5)
廣告