public static void main(String[] args) {
String[] trs ={"and","zuo","for","we","be","you"};
sort(trs);
for(int i=0;i<trs.length;i++){
System.out.println(trs[i]);
}
}
public static void sort(String[] str){
for(int i=0;i<str.length-1;i++){
String maxStr = str[i];
int index = i;
for(int j=i+1;j<str.length;j++){
if(maxStr.compareTo(str[j]) < 0){
maxStr = str[j];
index = j;
}
}
str[index] = str[i];
str[i] = maxStr;
}
}
简单的字符排序问题
最新推荐文章于 2022-09-27 09:37:09 发布