System.out.println(Integer.valueOf("001011"));, 居然 Exception in thread "main" java.lang.NumberFormatException: For input string: "001011" at java.lang.NumberFormatException.forInputString(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at java.lang.Integer.valueOf(Unknown Source) at sample.Main.main(Main.java:9)
复制下来的代码运行结果是: true 1011 false Exception in thread "main" java.lang.NumberFormatException: For input string: "?001011" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) 后面的字符串中有个不可见的空白或其它字符。
楼主,你也真是的,还千古奇BUGpublic class Main { public static void main(String[] args) { Provinces province = new Provinces("001011", "广东省"); System.out.println("001011".equals(province.code)); System.out.println(Integer.valueOf(province.code)); Provinces province2 = new Provinces("001011", "广东省"); System.out.println("001011".equals(province2.code)); System.out.println(Integer.valueOf(province2.code)); } }class Provinces { public Provinces(String code, String name) { super(); this.code = code; this.name = name; } public String code; public String name; }你试试这个代码
居然
Exception in thread "main" java.lang.NumberFormatException: For input string: "001011"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.valueOf(Unknown Source)
at sample.Main.main(Main.java:9)
true
1011
false
Exception in thread "main" java.lang.NumberFormatException: For input string: "?001011"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
后面的字符串中有个不可见的空白或其它字符。
public static void main(String[] args) {
Provinces province = new Provinces("001011", "广东省");
System.out.println("001011".equals(province.code));
System.out.println(Integer.valueOf(province.code)); Provinces province2 = new Provinces("001011", "广东省");
System.out.println("001011".equals(province2.code));
System.out.println(Integer.valueOf(province2.code));
}
}class Provinces {
public Provinces(String code, String name) {
super();
this.code = code;
this.name = name;
} public String code;
public String name;
}你试试这个代码
1011
true
1011