I'm creating a simple console app in Java and I have a trouble. This is my code:
boolean isActive = true;
Scanner scanner = new Scanner(System.in);
do {
try {
int option = scanner.nextInt();
switch (option) {
case 1:
System.out.println("Search By Registration number: " +
"\n------------------------------");
System.out.println("Enter registration number!");
String regNumber = scanner.nextLine();
if (regNumber == incorrect) {
continue; // return to case 1 and ask enter regnumber one more time
} else {
// do stuff
}
break;
case 2:
System.out.println("Exit the search option: ");
isActive = false;
break;
default:
System.out.println("Your selection was wrong. Try one more time!");
break;
}
} catch (InputMismatchException ex) {
System.out.println("Your selection was wrong. Try one more time!");
}
scanner.nextLine();
} while (isActive);
And I can't to return to case 1 if an error occured. So, if error occured, the user must get the message About entering the registration number one more time and so on.