public class ArrayTest3 { public static void main(String[] args){ System.out.println(toHex(60)); } //將十進制轉爲16進制 public static String toHex(int num){ char[] chs = new char[8];//定義容器,存儲的是字符,長度爲8.一個整數最多8個16進制數 int index = chs.length-1; for(int i = 0;i<8;i++) { int temp = num & 15; if(temp > 9){ chs[index] = ((char)(temp-10+'A')); }else { chs[index] = ((char)(temp+'0')); } index--; num = num >>> 4; } return toString(chs); } //將數組轉爲字符串 public static String toString(char[] arr){ String temp = ""; for(int i = 0;i<arr.length;i++){ temp = temp + arr[i]; } return temp; } }