我的这道题做出来为什么是3s,视频上是3c,好奇怪?大家帮忙看看,问题处在哪?
public class Reverse {
public static void main(String[] args) {
toHex(60);
}
private static void toHex(int num) {
// TODO Auto-generated method stub
StringBuffer sb = new StringBuffer();
for (int j = 0; j < 8; j++) {
int temp = num & 15;
if(temp>9){
sb.append((char)(num-10+'A'));
}else{
sb.append(temp);
}
//注意这里的右移的数字应该是num,而不是temp
num = num >>>4;
}
System.out.println(sb.reverse());
}
}
|
|