问题:关于2.3 jmu-Java-02基本语法-03-身份证排序 (9 分)
2024-08-31 21:47:59
输出未能排序
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;
}
}
}
}
最新文章
- 自用有线IP切换
- windows日常软件推荐
- 未能加载文件或程序集“Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed”或它的某一个依赖项。找到的程序集清单定义与程序集引用不匹配。
- 玩转iOS开发 - 简易的实现2种抽屉效果
- 赋值,copy和deepcopy
- Css中的变形及过渡动画
- Vue2.0环境搭建和测试demo
- [key]严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener(Spring配置异常)
- ubuntu-14.10下,安装gcc交叉编译器遇到问题及解决方法
- 初识Windous程序
- Xilinx ISE 14.1利用Verilog产生clock
- oracle session数激增排查过程
- java基础---->;java8中的函数式接口
- laravel----------如何优化laravel框架
- JSPatch实现原理详解<;二>;
- SpringBoot入门篇--读取资源文件配置
- bzoj 4689: Find the Outlier
- TestNG+Maven+IDEA 自动化测试(一) 环境搭建
- sort命令与cat区别
- django中的setting最佳配置小结