# From National Identity Card(NIC) print date of birth in java

Posted By: Java Examples - 11:09 AM

### Share

& Comment

The following numbering system is followed in order to assign this number:
• Digits 1 and 2: The year of birth
• Digits 3-5: The number of the day in the year on which the person's birth date falls.
• A male would be assigned the number 1-366 and a female the number 501-866. This is a way of confirming if the person's listed birth date is accurate. A male's birth date would be represented by the exact number of days, a female's birth date would be represented by the exact number of days + 500.
•    Example: The first five digits of the NIC for a male born on 1 January 1997   would be 97001; however, a female born on that same date would be 97501.
• Digits 6-8 are the serial number from the Record book maintained at the Department [for the Registration of Persons].
• Digit 9 is a check digit
• The letter V stands for voter and X for a non-voter. Example: a student who applies for a NIC at 16, at which age he/she does not have the right to vote, the number on his/her card will end with an X. Cards issued in 2007 (no exact date available) no longer make this distinction  everyone is issued numbers that end with the letter V.
Java version of NIC program is given bellow :

```/**
* To change this template, choose Tools | Templates and open the template in
* the editor.
*/
package age;

import java.util.Scanner;

/**
*
* @author ACHCHUTHAN
*/
public class NIC_Details {

String id;
int month[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

public NIC_Details() {
Scanner input = new Scanner(System.in);
System.out.println("Enter Your NIC Number \nLike : 000000000V");
id = input.next();
}

public int getYear() {
return (1900 + Integer.parseInt(id.substring(0, 2)));
}

public 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 Deatials of Date of Birth from NIC Number");
System.out.println("Year : " + N.getYear());
N.setMonth();
System.out.println("Sex : " + N.getSex());
}
}

```
Output of this program :

run:
Like : 000000000V
900733550v
Your Deatials of Date of Birth from NIC Number
Year : 1990
Month : 3
Date : 13
Sex : Male
BUILD SUCCESSFUL (total time: 12 seconds)