/**
* str(需要排序的字符串),desc(true:从小到大,false:从大到小)
* @param str
* @param desc
*/
public static void stringSort(String str,boolean desc){
char[] array=str.toCharArray();
if(desc){//从小到大排序
for (int i = 0; ifor(int j=0;j if(array[j]>array[j+1]){
char temp=array[j];
array[j]=array[j+1];
array[j+1]=temp;
}
}
}
System.out.print("从小到大:");
for (int i = 0; i < array.length; i++) {
if(i==array.length-1){
System.out.println(array[i]);
}else{
System.out.print(array[i]+",");
}
}
}else{
for (int i = 0; ifor(int j=0;j if(array[j]>array[j+1]){
char temp=array[j];
array[j]=array[j+1];
array[j+1]=temp;
}
}
}
System.out.print("从小到大:");
for (int i = 0; i < array.length; i++) {
if(i==array.length-1){
System.out.println(array[i]);
}else{
System.out.print(array[i]+",");
}
}
}
}