this code should check the accuracy of the typed date, if it's not accepted, the user should digit a new date, and so on until a correct date is typed. The problem is that after the first try, I type another date but then it returns an error.
String amPm"", temp="";
int hours=0,minutes=0,seconds=0;
boolean flag = true;
Scanner input1 = new Scanner(System.in);
input.useDelimiter(":");
do {
System.out.println("Insert a date: ");
hours= input.nextInt();
minutes = input.nextInt();
temp = input.nextLine();
seconds = Integer.parseInt(temp.substring(1, (temp.length() - 3)));
amPm = temp.substring((temp.length() - 2), temp.length());
if ((hours > 12 || hours < 1) || (minutes > 59 || minutes < 0) || (seconds > 59 || seconds < 0) ||
!(amPm.equalsIgnoreCase("AM")) || (amPm.equalsIgnoreCase("PM")))
System.out.println("Error - date not accepted.");
else
flag = false;
}
while(flag);
what am I doing wrong?