我将这个程序用于我的目的。导入 java.util.Scanner;
class NIC_Details {
String id;
int month[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
NIC_Details() {
Scanner input = new Scanner(System.in);
System.out.println("Enter Your NIC Number \nLike : 000000000V");
id = input.next();
}
int getYear() {
return (1900 + Integer.parseInt(id.substring(0, 2)));
}
int getDays() {
int d = Integer.parseInt(id.substring(2, 5));
if (d > 500) {
return (d - 500);
} else {
return d;
}
}
public void setMonth() {
int mo = 0, da = 0;
int days = getDays();
for (int i = 0; i < month.length; i++) {
if (days < month[i]) {
mo = i + 1;
da = days;
break;
} else {
days = days - month[i];
}
}
System.out.println("Month : " + mo + "\nDate : " + da);
}
public String getSex() {
String M = "Male", F = "Female";
int d = Integer.parseInt(id.substring(2, 5));
if (d > 500) {
return F;
} else {
return M;
}
}
public static void main(String[] args) {
NIC_Details N = new NIC_Details();
System.out.println("Your Details of Date of Birth from NIC Number");
System.out.println("Year : " + N.getYear());
N.setMonth();
System.out.println("Sex : " + N.getSex());
}
}
但是当我输入像这样的 NIC 号码 93031* ** 它给出了这个细节
Enter Your NIC Number
Like : 000000000V
93031******
Your Details of Date of Birth from NIC Number
Year : 1993
Month : 2
Date : 0
Sex : Male
请告诉我这里发生了什么。