After the user enters a 2 digit hexadecimal the program will continue unless they enter a 1 digit or 3-digit and more hexadecimal, I want the user to try again however after the first "invalid" message in the console when the user enters an incorrect value for the second time it goes through and is not stopped by an "invalid" message.
import java.util.Scanner;
public class Dance6 {
public static void main(final String[] args) {
Scanner sc = new Scanner(System.in);
String hexadecimal;
System.out.println("Please enter a 2-digit hexadecimal value : ");
hexadecimal = sc.nextLine();
if (hexadecimal.length() != 2) {
System.out.println("Invalid input, please try again : ");
sc.next();
}
}
}