zoukankan      html  css  js  c++  java
  • 问题:关于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;
                    }
                }
            }
                        


            }   
  • 相关阅读:
    折腾了好久的输入法显示已禁用
    文件下载上传小工具
    隐藏进程命令行参数,例如输入密码等高危操作
    创建并使用https证书
    编译lua可执行程序
    使用msys2在window下构建和使用Linux的软件
    golang遍历时修改被遍历对象
    使用shell发送邮件,方便快捷
    关于golang的time包总结
    获取Win和Linux系统启动时间,类似uptime功能,用于判断是否修改过系统时间
  • 原文地址:https://www.cnblogs.com/zlshy/p/11524090.html
Copyright © 2011-2022 走看看