class SearchList
{
public static void change(int val,int base)//参数依次为:值,进制
char[] chs = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
char[] chs2 = new char[8];
int pos = chs2.length;
int offset;
if (base == 16)
{
offset = 4;
}
else if (base == 8)
{
offset = 3;
}
else if (base == 2)
{
offset = 1;
}
else
System.out.println("您输入的数值有误");
while (val != 0)
{
int temp = val & (base - 1);
chs2[--pos] = chs[temp];
val >>>= offset;
}
for (;pos < chs2.length ;pos ++ )
{
System.out.print(chs2[pos]+" ");
}
}
public static void main (String [] args)
{
change(60,16);
}
}
提示offset未定义
本来if我是用switch的,担示offset未定义,改成if还是一样的结果.
请教为什么... |