小弟菜鸟 希望大神来解答
程序编译时没有问题 运行时出错了 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 16
at Shuzu6.trans(Shuzu6.java:25)
at Shuzu6.main(Shuzu6.java:5)
---------------------------------------------------------------------------------------------------------------------------
class Shuzu6
{
public static void main(String[] args)
{
trans(60,4,16);
}
public static void trans(int x,int y,int z) //x:所要转化的数。y:需要&的位数。z:所要转化的进制数。
{
if(x==0)
{
System.out.println(0);
return;
}
char[] b={'0','1','2','3',
'4','5','6','7',
'8','9','A','B',
'C','D','E','F'};
char[] a=new char[32];
int m=a.length;
while(x!=0)
{
int n=x&z;
a[--m]=b[n];
x=x>>>y;
}
for(int p=m;p<a.length;p++)
{
System.out.print(a[p]);
}
}
}
|
|