import javax.swing.*;public class sort{
    public static void main(String[] args){
        String [] str=new String[11];
        //input
        for(int count=1;count<=10;count++)
           str[count]=JOptionPane.showInputDialog
            ("please input the "+count+" String:");
        //sort
        int i=0;
        int j=0;
        for(i=2;i<=10;i++){
            if(str[i]<str[i-1]){
                str[0]=str[i];
                str[i]=str[i-1];
                for(j=i-2;str[0]<str[j];j--)
                    str[j+1]=str[j];
                str[j+1]=str[0];
            }
        }
        //output
        for(int count=1;count<=10;count++)
            System.out.println(count+";"+str[count]);
    }
}

解决方案 »

  1.   

    呵呵,java的基础数据结构中就有排序函数啊:)
    如:Collection 类的sort()方法就实现了List接口的数据结构排序!
    List people = new LinkedList();
    Collection.sort(people);
    搞定!!
      

  2.   


    public class sort{
        public static void main(String[] args){
            String [] str=new String[11];
            System.in.readBufferedReader keyboard =
                   new BufferedReader(new InputStreamReader(System.in), 1);
            //input
            for(int count=1;count<=10;count++)
               str[count]= keyboard.readLine();}
            //sort
            int i=0;
            int j=0;
            for(i=2;i<=10;i++){
                if(str[i]<str[i-1]){
                    str[0]=str[i];
                    str[i]=str[i-1];
                    for(j=i-2;str[0]<str[j];j--)
                        str[j+1]=str[j];
                    str[j+1]=str[0];
                }
            }
            //output
            for(int count=1;count<=10;count++)
                System.out.println(count+";"+str[count]);
        }
    }