Hey all, I am definitely new here and new to java.
I have a program assignment for a intro to programming class that requires us to have a user enter a password and re prompt the entry until it is correct. I am not looking necessarily for the correct code but for pointers as to what exactly I am doing wrong. I suppose my issue is getting to the beginning of the "main" loop that counts characters while testing and then prompting the user for the right values later. I'll post what I have and if anyone has any pointers it would be much appreciated.
/** A program to have a user enter a password with * specified requirements, and have the user re-enter * a password until those requirements are met.*/ import java.util.Scanner; //allows user keyboard input public class ValidatePassword { public static void main(String[] args) { String passwordRequirements ="Enter a password. Must have \n" //String describing password requiremts + "at least two uppercase letters, \n" + "at least three lowercase letters \n" + "and at least one digit."; String password; //String that holds the users password Scanner stdin = new Scanner(System.in); //Scanner class that allows user input int passwordLength; //integer storing password length /*These next lines get the inital user password after defining the pass word requirements and then parrots back the password and stores and shows the length*/ System.out.println(passwordRequirements); System.out.println("Enter your password: "); password = stdin.nextLine(); passwordLength = password.length(); System.out.println("The password you entered is " + password); //These are for System.out.println("The password length is " + passwordLength); //testing only int i; //integer of position of character in the string char c; //character used to determine upper/lower case int lowerCount = 0; //integer of how many lower case characters there are int upperCount = 0; //integer of how many upper case characters there are int digitCount = 0; final int MIN_LOWER = 3; //min number of lower case letters needed final int MIN_UPPER = 2; //min number of upper case letters needed final int MIN_DIG = 1; //min number of numeric digits needed /*This section tests the password entered and has the user correct any wrong elements*/ while (passwordLength < 6) //makes sure that password isn't too short { System.out.println("Your password is too short, please enter password: "); password = stdin.nextLine(); passwordLength = password.length(); } for(i = 0; i < passwordLength; i++) { c = password.charAt(i); if(Character.isUpperCase(c)) { upperCount++; } else if(Character.isLowerCase(c)) { lowerCount++; } else if(Character.isDigit(c)) { digitCount++; } } if(upperCount != MIN_UPPER) { while(upperCount < MIN_UPPER) { System.out.println("Password must contain at least 2 upper case letters!"); System.out.println("Please enter a new password: "); password = stdin.nextLine(); passwordLength = password.length(); } } if(lowerCount != MIN_LOWER) { while(lowerCount < MIN_LOWER) { System.out.println("Password must contain at least 3 lower case letters!"); System.out.println("Please enter a new password: "); password = stdin.nextLine(); passwordLength = password.length(); } } if(digitCount != MIN_DIG) { while(digitCount < MIN_DIG) { System.out.println("Password must contain at least 1 digit!"); System.out.println("Please enter a new password: "); password = stdin.nextLine(); passwordLength = password.length(); } } System.out.println("The password you entered is " + password); System.out.println("Password length is " + passwordLength); System.out.println("Upper Count: " + upperCount); System.out.println("Lower Count: " + lowerCount); System.out.println("Digit Count: " + digitCount); } }