5黑马币
class Number
{
public static void main(String[] args)
{
System.out.println("Hello World!");
System.out.println("----------------");
toBin(6);
toHex(60);
}
public static void toHex(int num)
{ char[] chs = {'0','1','2','3'
,'4','5','6','7'
,'8','9','A','B'
,'C','D','E','F'};
char[] arr = new char[8];
int pos = arr.length;
while (num!=0)
{
int temp =num & 15;
//System.out.println(arr[pos]);
arr[--pos] = chs[temp];
num = num >>> 4;
}
System.out.println("pos="+pos);
for (int x=pos;x<arr.length ;x++ )
{
System.out.print(arr[x]+',');
}
}
}
结果 怎么是95111
|
最佳答案
查看完整内容
System.out.print(arr[x]+',')
;这句代码错了,要打印的字符串,你这样变成两个字符相加再打印编码。应改为
System.out.print(arr[x]+“,”)
变为字符串
|