public class yiwei { public static void main(String[] args){ int x=1234; heihei i =new heihei(x); String p=Integer.toBinaryString(x); Integer q=Integer.parseInt(p); System.out.println("x的2进制表示为:"+Integer.toBinaryString(x)); System.out.println("右移4位为:"+(q>>4)); } } class heihei{ int p; heihei(int q){ p=q; }
int bin(int p){ if(p<2) return p; return bin(p/2)+bin(p%2); } } 报错如下 Exception in thread "main" java.lang.NumberFormatException: For input string: "10011010010" at java.lang.NumberFormatException.forInputString(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at yiwei.main(yiwei.java:7) 是在这行报的
报错行:Integer q=Integer.parseInt(p);
public static int parseInt(String s) throws NumberFormatException将字符串参数作为有符号的十进制整数进行分析。
public class yiwei {
public static void main(String[] args){
int x=1234;
heihei i =new heihei(x);
String p=Integer.toBinaryString(x);
Integer q=Integer.parseInt(p);
System.out.println("x的2进制表示为:"+Integer.toBinaryString(x));
System.out.println("右移4位为:"+(q>>4));
}
}
class heihei{
int p;
heihei(int q){
p=q;
}
int bin(int p){
if(p<2) return p;
return bin(p/2)+bin(p%2);
}
}
报错如下
Exception in thread "main" java.lang.NumberFormatException: For input string: "10011010010"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at yiwei.main(yiwei.java:7)
是在这行报的
throws NumberFormatException将字符串参数作为有符号的十进制整数进行分析。