package example;
import javax.swing.JOptionPane;
public class Identity {
public static void main(String[] args) {
// TODO Auto-generated method stub
String ID;
int year,month,day,lent,province;
ID=JOptionPane.showInputDialog("請輸入你的身份證號:");
lent=ID.length();
if(lent!=18){
JOptionPane.showMessageDialog(null, "身份證長度輸入錯誤","warning",0);
return ;
}
province=Integer.parseInt(ID.substring(0,2));
year=Integer.parseInt(ID.substring(6,10));
month=Integer.parseInt(ID.substring(10,12));
day=Integer.parseInt(ID.substring(12,14));
int array[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
if (province<=00||province>=51){
JOptionPane.showMessageDialog(null, "省市錯誤","warning",0);
}
else if(year<=1500||year>2015){
JOptionPane.showMessageDialog(null, "年份錯誤","warning",0);
}
else if(month<1||month>12){
JOptionPane.showMessageDialog(null, "月份錯誤","warning",0);
}
else if(year%400==0||year%4==0&&year%100!=0){
if(month==2&&(day>29||day<=0)){
JOptionPane.showMessageDialog(null, "日子錯誤","warning",0);
}
}
else if(array[month]<=day||day<=0){
JOptionPane.showMessageDialog(null, "日子錯誤","warning",0);
}
else
JOptionPane.showMessageDialog(null, "身份證輸入合法","Yes",JOptionPane.PLAIN_MESSAGE);;
}
}
LZ你的程序我一個字都沒改