JS实现字符排序
public class rrrr {
public static void main(String args[]) {
String str = "p9z1gxy32jm0wq4uf6mbrva5ie8sd7clkto";
String str2 = "";
char tempstr = 0;
char[] arrstr = str.toCharArray(); //把字符串转换为字符数组
for(int i = 0;i < arrstr.length;i++) //冒泡程序,由小到大排序
{
for(int j = 0;j < arrstr.length - 1;j++)
{
//System.out.print(arrstr[j]);
if(arrstr[j] > arrstr[j+1])
{
tempstr = arrstr[j];
arrstr[j] = arrstr[j+1];
arrstr[j+1] = tempstr;
}
}
}
for (int k = 0;k < str.length();k++) //循环数组返回结果到字符串
{
if(str2 != "") str2 += arrstr[k];
else str2 = arrstr[k]+"";
}
System.out.println(str2); //显示
}
}