911288373 发表于 2012-12-12 19:33
该怎么返啊?
帮把代码改改?
class JiSuanqi
{
public static void main(String[] args)
{
toBin(7);
toBa(89);
toHex(60);
}
public static void trans(int num, int base,
int offset)//这里因为你里面是输出语句,所以不需要返回值,也没有返回接收啊
{
if(num==0)
{
System.out.println(0);//不需要返回就不需要return;
}
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<arr.length ;x++ )
{
System.out.println(arr[x]);
}
}
public static void toBin(int num)
{
trans(num,1,1);
}
public static void toBa(int num)
{
trans(num,7,3);
}
public static void toHex(int num)
{
trans(num,15,4);
}
}
|