JAVA题目字母排序,请高手编下.

来源:百度知道 编辑:UC知道 时间:2024/06/23 23:12:43
比如一个数组存放{g,s,A, a,U,K,e,k}
请排序为:{A,a,e,g,K,k,s,U}
我没搞出来,郁闷.帮忙写下啊
Five00写的我运行了下,好象排序顺序有点不正确,
doonyman写的看不懂,解释下吧

这个已经可以运行并证明是正确的:
public class Sort {
public static void main(String[] args)
{
char a[]={'g','s','A','a','U','K','e','k'};
int l=a.length;
char temp;
int j;
int n=l-1;
for(int i=0;i<l;i++)
{
for(j=0;j<n;j++)
{
//System.out.print(" "+(j+1));
if(Character.toUpperCase(a[j])>=Character.toUpperCase(a[j+1]))
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
n--;
}
for(int k=0;k<l-1;k++)
{
if(Character.toUpperCase(a[k])==Character.toUpperCase(a[k+1]))
{
temp=a[k];
a[k]=a[k+1];
a[k+1]=temp;
}
}
for(int k=0;k<l;k++)
{
System.out.print(" &