• 问题:关于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;
                    }
                }
            }
                        


            }   
  • 相关阅读:
    Python操作Word:常用对象介绍
    Python入门教程 超详细1小时学会Python
    用几何画板画七边形的方法
    用ChemDraw画3D图的方法
    Chem 3D模型的参数值更改方法
    Chem 3D中怎么创建立体模型
    在几何画板中输入绝对值的方法
    怎么给几何画板文字加立体阴影效果
    几何画板放大和缩小的方法
    ChemDraw Pro和ChemBio3D Ultra有什么区别
  • 原文地址:https://www.cnblogs.com/zlshy/p/11524090.html
Copyright © 2020-2023  润新知