import java.util.*;
class ArrayTest2
{
public static void main(String[] args)
{
toBin(6);
}
public static void toBin(int num)
{
//StringBuffer s = nuw StringBuffer();
//定义二进制表
char[] ch = new char[]{'0','1'};
//定义临时存储器
char[] arr = new char[32];
//定义指针
int p = arr.length;
while (num>0)
{
arr[--p] = ch[num & 1];
num = num >>> 1;
}
for(int i=p; i<arr.length; i++)
{
System.out.print(arr[p]);
}
}
}
编译无错误,运行无异常,就是出不来正确结果
结果输出:
111
求真相,谢谢
|