黑马程序员技术交流社区

标题: Java基础细节总结(数组05) [打印本页]

作者: 阿凡提不买驴    时间: 2013-6-29 14:12
标题: Java基础细节总结(数组05)
3、十进制—十六进制

public static void toHex(int num)

{

StringBuffer sb = new StringBuffer();

for(int x=0;x<8;x++)

{

int temp=num & 15;

if(temp>9)

sb.append((char)(temp-10+'A'));

else

sb.append(temp);

num=num>>>4;

}

System.out.println(sb.reverse());

}

4、查表法进制转换优化

public static String trans(int num;int base;int offset)

{

if(num==0)

{

System.out.println(0);

return 0;

}

char[] chs = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};

char[] arr = new char[32];

int pos = arr.length;

while(num!=0)

{

int temp = num & base;

arr[--pos] = chs[temp];

num = num>>>offset;

}

for(int x=pos;x

{

System.out.print(arr[x]);

}

}

五、二维数组

注意二维数组名和一维数组名之间赋值的正确判断

int [] x,y[];

int [] x;

int [] y[];

a、x[0] = y; error

b、y[0] = x; yes

c、y[0][0]=x; error

d、x[0][0]=y; error

e、y[0][0]=x[0] yes

f、x=y error






欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2