I am trying to make this code run properly. If I enter a date of birth wrong first, the program returns me null, if I enter the dob correctly from the first time it returns the correct dob. What I am doing wrong?
public static Date convertDOB() { //Date of Birth Method
System.out.println("Enter Date Of Birth: ");
String dob = in.nextLine();
SimpleDateFormat formater = new SimpleDateFormat("dd/MM/yyyy");
Date realdob = null;
try {
realdob = formater.parse(dob);
} catch (ParseException e) {
System.out.println("In-correct format. Format should be dd/mm/yyyy");
convertDOB();
}
return realdob;
}