public class test01 {
public static void main(String[] args) {
int[] str = {1212,123,132,15,11,16,5,12,44} ;
maopao(str) ;
}
public static void maopao(int str[]){
int temp = 0 ;
for(int i=0;i
int s1 = (str[j]+"").length() ;//前一个数的长度
int s2 = (str[j+1]+"").length() ;//后一个数的长度
if(s1>s2){//如果第一个数的长度比第二个大,例如123和22
String splitLong = (str[j]+"").substring(0,s2) ;//把较长的那个数拆分成和短数一样长
/**
* 原理就是比较前一个数和后一个数的长度,如果长度一样,那么比较大的肯定
* 靠后,如果长度不一样就拆成一样的比较。
*/
if(Integer.parseInt(splitLong)>=Integer.parseInt(str[j+1]+"")){
//如果那个较长的数拆分下来的这个数还比那个短数大就进行冒泡排序。
temp = str[j] ;
str[j] = str[j+1] ;
str[j+1] = temp ;
}
}else if(s1
if(Integer.parseInt(splitLong)
str[j] = str[j+1] ;
str[j+1] = temp ;
}
}else{//这个是相等的情况
if(Integer.parseInt(str[j]+"")>Integer.parseInt(str[j+1]+"")){
temp = str[j] ;
str[j] = str[j+1] ;
str[j+1] = temp ;
}
}
}
for(int x=0;x
}
System.out.println();
}
for(int i=0;i
}
}
}
不知道还有没有更简便的方法呢?