public static void main(String[] args) { int []arr={2,2,2,9,7,7,7,3,3,3,6,6,6,0,0,0}; int len=arr.length; char[][]kRadix=new char[len][]; int k=3; int maxLen=0; for (int i = 0; i < len; i++) { kRadix[i]=new StringBuilder(Integer.toString(arr[i],k)).reverse().toString().toCharArray(); if (kRadix[i].length>maxLen) maxLen=kRadix[i].length; } int [] reArr=new int[maxLen]; for (int i = 0; i < len; i++) { for (int j = 0; j < maxLen; j++) { if (j>= kRadix[i].length) reArr[j]+=0; else reArr[j]+=(kRadix[i][j]-'0'); } } int res=0; for (int i = 0; i < maxLen; i++) { res+=(reArr[i]%k)*(int)(Math.pow(k,i)); } System.out.println(res); } 数组的数转成3进制做不进位加法,数组只有9出现一次,其余出现3次,其余做不进制加法都为0 k个相同的k进制数做不进制加法,结果为0 答案: