Need help with a program that checks if the entered string has uppercase, lowercase and special chars (SOLVED)

Hi everyone, I’ve been trying to create a program that checks if the entered string contains uppercase, lowercase and special character and if the string is at least 6 characters long. Using eclipse it says “The value of the local variable x is not used” where x is the boolean expressions (containDigit, containLowerCase, containUpperCase, containSpecialCharacter). I’ve tried searching, but no luck. excuse my terrible programming, I’m very new.

EDIT: I’ve found the problem and it was using (=) instead of (==) in the end. I feel dumb now.

public static void main(String[] args) {
	Scanner kb = new Scanner(System.in);
	System.out.println("Enter your password.");
	String password = kb.nextLine();
	boolean containDigit = false;
	boolean containLowerCase = false;
	boolean containUpperCase = false;
	boolean containSpecialCharacter = false;

	if (password.length() < 6)
		System.out.println("Your password must be at least 6 characters long.");
	
	else for (int i = 0; password.length() > i; i++ ) {
		if (Character.isDigit(password.charAt(i)))
			containDigit = true;
		
		else if (Character.isLowerCase(password.charAt(i))) 
			containLowerCase = true;
		
		else if (Character.isUpperCase(password.charAt(i)))
			containUpperCase = true;
		
		else if (password.charAt(i) == '!'|| password.charAt(i) == '@'|| password.charAt(i) == '#'|| password.charAt(i) == '$'|| password.charAt(i) == '%'|| password.charAt(i) == '^'|| password.charAt(i) == '&'|| password.charAt(i) == '*'|| password.charAt(i) == '('|| password.charAt(i) == ')' || password.charAt(i) == '-' || password.charAt(i) == '+')
			containSpecialCharacter = true;
	}
	if (containDigit = false)
		System.out.println("The password must contain a digit.");
	if (containLowerCase = false)
		System.out.println("The password must contain a lowercase English character.");
	if (containUpperCase = false)
		System.out.println("The password must contain an uppercase English character.");
	if (containSpecialCharacter = false)
		System.out.println("The password must contain at least one special  character ( !@#$%^&*()-+ ).");


}
1 Like