i just can't figure out what's wrong with this.
1. suppose i enter 9-3-1991 as the birthdate, this should return 18. but it returns 17. //wrong
2. suppose i enter 2-9-1991 as the birthdate, this returns 18. //correct
what's wrong with my code?
Code:private static int ageCalc(int mm, int dd, int yyyy) { Calendar currentDate = Calendar.getInstance(); Calendar birthDate = new GregorianCalendar(); birthDate.set(yyyy, mm, dd); age = currentDate.get(Calendar.YEAR) - birthDate.get(Calendar.YEAR); birthDate.add(Calendar.YEAR, age); if(currentDate.before(birthDate)) { age--; } return age; }


Reply With Quote


Bookmarks