I have this problem with my code. It reads if the password has at least 10 characters but about the digits, it doesn't work. It always tells me that the password must contain at lease 2 digits.
public class EsercizioPassword {
static int passLength = 10;
static String pass = "hello1221";
public static void main(String[] args) {
checkPass();
}
public static void checkPass() {
int digit=0;
for (int i = 0; i < pass.length(); i++) {
if(Character.isDigit(pass.charAt(i))) {
digit++;
if(digit<2) {
System.out.println("At least 2 digits");
return;
}
}
if (!Character.isLetterOrDigit(pass.charAt(i))) {
System.out.println("Password must contains only Lettere or Digit ");
return;
}else if (pass.length() < 10) {
System.out.println("Password must contains at least 10 characters");
return;
}
}
System.out.println("Correct password");
}
}