public class Lx06
{
public static void main(String[] args)
{
show(13);
}
public static void show(int num)
{
char[] arr = {'0','1'};
char[] min = new char[32];
int pos = min.length;
while (num!=0)
{
int tem = num&1;
min[--pos] = arr[tem];
num = num>>>1;
}
for (int x= pos;x<min.length ;x++ )//是x<min.length,不是<arr.length.
{
System.out.print(min[x]);
}
}
}
for循环的条件写错了,应该是x<min.length。 |