Could Kindly Check Fix Code Please Cannot Get Work Please Follow Code Strictly Without Cha Q43891784
Could you kindly check and fix my code please? I cannot get itto work. PLEASE FOLLOW MY CODE STRICTLY WITHOUT CHANGING ITENTIRELY!
Problem: Some websites impose certain rules forpasswords. Write a method that checks whether a string is a validpassword. Suppose the password rules are as follows:
■ A password must have at least techaracters.
■ A password consists of only letters and digits.
■ A password must contain at least three digits.
Write a program that prompts the user to enter a password anddisplays “Valid Password” if the rules are followed or “InvalidPassword” otherwise.
My code:
import java.util.*;
public class Exercise06_18 {
public static void main(String[] args) {
// Create a scanner class
Scanner input = new Scanner(System.in);
// Prompt the user to enter three integers
System.out.println(“Please enter a password: “);
String password = input.next();
checkPassword(password);
}
public static void checkPassword(String pass) {
int digitCount = 0;
boolean passwordCondition = true;
if(pass.length() < 10) {
passwordCondition = false;
}
for(int i = 0; i < pass.length(); i++) {
if(!(Character.isDigit(pass.charAt(i)))) {
passwordCondition = false;
}
if(!(Character.isLetter(pass.charAt(i)))) {
passwordCondition = false;
}
if((Character.isLetter(pass.charAt(i)))) {
passwordCondition = false;
digitCount++;
}
if (digitCount < 3) {
passwordCondition = false;
}
}
if(passwordCondition = true) {
System.out.println(“Valid password.”);
}
else if(passwordCondition = false) {
System.out.println(“Invalidpassword. “);
}
}
}
Expert Answer
Answer to Could you kindly check and fix my code please? I cannot get it to work. PLEASE FOLLOW MY CODE STRICTLY WITHOUT CHANGING …
OR