/*
Enter your passwords:1234
Invalid password.
Enter your passwords:~!4456678999
Invalid password.
Enter your passwords:The big bang 12
Invalid password.
Enter your passwords:BambooDace12
Valid password.
*/
import java.util.Scanner;
publicclass CheckPassword {
publicstaticvoidmain(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter your passwords:");
String passwords = input.nextLine();
if (checkPasswords(passwords))
System.out.println("Valid password.");
else
System.out.println("Invalid password.");
}
publicstatic boolean checkPasswords(String p) {
int digitsCount = 0;
for (int i = 0; p.length() >= 8 && i < p.length(); i++) {
if (Character.isLetterOrDigit(p.charAt(i))) {
if (Character.isDigit(p.charAt(i)))
digitsCount++;
} elsebreak;
}
if (digitsCount >= 2)
returntrue;
elsereturnfalse;
}
}