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不会执行,求解答,谢谢