由于最大数可能超过Integer.MAX_VALUE,返回值用String返回:
static String maxNum(int [] array) {
for (int i = 0;i < array.length;i ++) {
for (int j = i;j < array.length;j ++) {
int tmp;
int maxI =array[i];
int maxJ =array[j];
maxI = Integer.valueOf(String.valueOf(array[i]) + String.valueOf(array[j]));
maxJ = Integer.valueOf(String.valueOf(array[j]) + String.valueOf(array[i]));
if (maxI > maxJ) {
tmp = array[j];
array[j] = array[i];
array[i] = tmp;
}
}
}
StringBuilder stringBuilder = new StringBuilder();
for (int i = array.length - 1;i >= 0;i --) {
stringBuilder.append(array[i]);
}
return stringBuilder.toString();
}
帖子还没人回复快来抢沙发