public?class?CharTest?{
static?Scanner?sc=new?Scanner(System.in);
public?static?void?main(String[]?args)?{
System.out.println("請輸入隨機字母!");
String?str=sc.nextLine().replaceAll("[^\\w]+",?"").replaceAll("\\d",?"");
StringBuilder?stb=new?StringBuilder();
char[]?chs=str.toCharArray();
System.out.println("\n妳輸入的是:"+str);
//排序!
for(int?i=1;i<chs.length;i++)?{
for?(int?j?=?i;?j?>0;?j--)?{
if(chs[j]<chs[j-1])?{
char?tem=chs[j];
chs[j]=chs[j-1];
chs[j-1]=tem;
}
}
}
stb.append(chs);
System.out.println("\n排序:大寫-->小寫-->正序排列:"+stb);
System.out.println("\n排序:小寫-->大寫-->倒序排列:"+stb.reverse());
}
}