public static boolean hasUpperCase(String str) throws PasswordUpperCase { boolean hasUpperCase = false; //checks the password for an upper case letter for (char c : str.toCharArray()) { if(Character.isUpperCase(c)) { hasUpperCase = true; } } if (!hasUpperCase) { throw new PasswordUpperCase(); } } /*************OR************/ public static boolean hasUpperCase(String str) throws PasswordUpperCase { boolean hasUpperCase = false; //checks the password for an upper case letter for (int c = 0; c < str.length() && !hasUpperCase; c++) { if(Character.isUpperCase(c)) { hasUpperCase = true; } } if (!hasUpperCase) { throw new PasswordUpperCase(); } }