问题:关于2.3 jmu-Java-02基本语法-03-身份证排序 (9 分)

输出未能排序
    import java.util.Scanner;
    import java.util.Arrays;
    public class Main {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int n =sc.nextInt();
     sc.nextLine();
            String[] ID =new String[n];
            for (int i=0;i<n;i++) {
                ID[i]=sc.nextLine();
            }
            for (int i=0;i<n;i++) {
                for (int j=i;j<n-1;j++) {
                    if (Integer.parseInt(ID[j].substring(6,10))>Integer.parseInt(ID[j+1].substring(6,10))) {
                        String Tmp = ID[j];
                        ID[j] =ID[j+1];
                        ID[j+1]= Tmp;
                        
                    }else if(Integer.parseInt(ID[j].substring(6,10))==Integer.parseInt(ID[j+1].substring(6,10))){
                        if(Integer.parseInt(ID[j].substring(10,12))>Integer.parseInt(ID[j+1].substring(10,12))){
                            String Tmp = ID[j];
                            ID[j]=ID[j+1];
                            ID[j+1]=Tmp;
                        }
                        else if (Integer.parseInt(ID[j].substring(10,12))==Integer.parseInt(ID[j+1].substring(10,12))){
                             if (Integer.parseInt(ID[j].substring(12,14))>Integer.parseInt(ID[j+1].substring(12,14))) {
                                 String Tmp =ID[j];
                                 ID[j]=ID[j+1];
                                 ID[j+1]=Tmp;
                             }
                        }
                    }
                }
            }
            for(;;) {
                String tmp=sc.nextLine();
                if (tmp.equals("sort1"))
                {
                    for(int i=0;i<n;i++) {
                        System.out.println(ID[i].substring(6,10)+"-"+ID[i].substring(10,12)+"-"+ID[i].substring(12,14));
                    }
                    }else if (tmp.equals("sort2")) {
                    for (int i=n-1;i>=0;i--) {
                        System.out.println(ID[i]);
                    }
                }else{
                    
                    System.out.println("exit");
                    break;
                }
            }
        }
                    


        }   
posted @ 2019-09-15 20:35  阢Lana  阅读(1115)  评论(0编辑  收藏  举报
/*别去做新时代教化的奴隶,别轻易去向别人看齐——*/
正在加载今日诗词....
© options->title(); ?>. Typecho 强力驱动'); ?>.