Hi, Im new to Java so Im trying out some excersises. The question asks to input IC number then get the digits for birthdate then display the complete birthdate. The output of this IC number : 900208-08-5386 ,should be something like this : 08 February 1990.

I probably have to create an array of months first, something like :

String months[] = new String[13];//create array named months, size 13
months[0] = null ;
months[1] = "January";
months[2] = "February";
months[3] = "March";
months[4] = "April";
months[5] = "May";
months[6] = "June";
months[7] = "July";
months[8] = "August";
months[9] = "September";
months[10] = "October";
months[11] = "November";
months[12] = "December";

then use substring() to get the first 6 digits for the birth date.

String BirthDate = ic.substring(0, 6);

then i have to get the month by using substring() as well(I guess)

Birthdate.substring(2, 3);

how do i get the month(February) from the array from the number(02)?

1 Year
Discussion Span
Last Post by JamesCherrill

When you have the month number as a String you can convert that to an Integer using the Integer.parseIntmethod (see API doc for details). Then you can use that Integer as an index to get the correct element from you month name array.

There is a SimpleDateFormat class that does that kind of parsing and formatting of date info, but maybe that's not what you teacher is looking for here

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.