先将-1转换成二进制字符串,再讲改字符串转换成整数为什么报错。如何解决呢?程序如下:
public class TestIncome {
public static void main(String[] args) {
String b=Integer.toBinaryString(-1);
System.out.println(b);
System.out.println(Integer.parseInt(b));
}
}
运行结果:
11111111111111111111111111111111
Exception in thread "main" java.lang.NumberFormatException: For input string: "11111111111111111111111111111111"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:495)
at java.lang.Integer.parseInt(Integer.java:527)
at com.baidu.ar.income.model.TestIncome.main(TestIncome.java:7)
|
|