思路:(1)总体思路就是通过双层循环进行排序,从大到小一次排序
(2)将数字转化为字符串相加之后再转回为数值比较大小,通过简单交换排序的方法
public static String SortMax(int number[]){
int max = 0;
int min = 0;
int tempX,tempY;
Integer x,y;
StringBuffer s = new StringBuffer();
for (int i = 0; i < number.length; i++) {
for (int j = i + 1; j < number.length; j++) {
x = number[i];
y = number[j];
tempX = Integer.parseInt(x.toString() + "" + y.toString());
tempY = Integer.parseInt(y.toString() + "" + x.toString());
//关键点,转为String类型拼接起来,再转回int类型进行比较
if(tempX > tempY){
max = x;
min = y;
}
else{
max = y;
min = x;
}
number[i] = max;
number[j] = min;//其实就是简单交换排序的变形
}
}
for (int i = 0; i < number.length; i++) {
s.append(number[i]);
}
return s.toString();
}