public static String largestNumber(int[] nums) {
String[] array = new String[nums.length];
for (int i = 0; i < nums.length; i++) {
array[i] = String.valueOf(nums[i]);
}
String temp;
for (int i = 0; i < array.length; i++) {
for (int j = i + 1; j < array.length; j++) {
if ((array[i] + array[j]).compareTo(array[j] + array[i]) < 0) {
temp = array[i];
array[i] = array[j];
array[j] =temp;
}
}
}
if (array[0].equals("0")) {
return "0";
} else {
return Arrays.toString(nums).replace("[","").replace("]","").replace(", ","");
}
}
public static void main(String[] args) {
int[] nums = {5,56,67,110};
System.out.println(largestNumber(nums));
}
最后打印结果是:55667110