噫吁汐 2022-02-22 16:37 采纳率: 95%
浏览 46
已结题

java,判断身份证的有效性


public judge(){
        System.out.println("请输入参数");
    }

    public judge(String s){

        if(s.length()<=17){
            System.out.println("号码位数错误");
        }else {
            Pattern p = Pattern.compile("\\d{18,19}");
            String year=s.substring(6,9);
            String month=s.substring(10,11);
            String day=s.substring(13,14);
            if(new Integer(year).intValue()>2022){
                System.out.println("身份证号错误");
            }
            if(new Integer(month).intValue()>12){
                System.out.println("身份证号错误");
            }
            if(new Integer(day).intValue()>31){
                System.out.println("身份证号错误");
            }
            Matcher m = p.matcher(s);
            t = m.matches();
        }
    }

    public boolean method(){
        return t;
    }
}
public class main {
    public static void main(String[] args) {
        judge j=new judge("111111202302280000");
        System.out.println(j.method());
    }
}

输出为true。
我不太清楚为什么在judge构造方法中那三个if不会执行,求解答,谢谢

  • 写回答

3条回答 默认 最新

  • 冷冷的天气 2022-02-22 16:48
    关注

    s.substring(6,10)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 3月2日
  • 已采纳回答 2月22日
  • 创建了问题 2月22日

悬赏问题

  • ¥15 Llama如何调用shell或者Python
  • ¥20 eclipse连接sap后代码跑出来空白
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案