title: Password Checking, Verification and Requirements
body: <p>I have a problem that requires at least 2 uppercase letters, at least 2 lowercase letters and 2 digits. </p>
  
  <p>Here is the exact problem:</p>
  
  <blockquote>
    <p>Write an application that prompts the user for a password that contains at least two uppercase letters, at least two lowercase letters, and at least two digits. After a password is entered, display a message indicating whether the user was successful or the reason the user was not successful.</p>
    
    <p>For example, if the user enters "Password" your program should output:
    Your password was invalid for the following reasons:
    uppercase letters
    digits </p>
    
    <p>If a user enters "P4SSw0rd", your program should output:
    valid password</p>
  </blockquote>
  
  <p>Here is my coding so far, I am having the problem of including output lines. For example, if someone doesn't have 2 capital letters AND doesn't have 2 letters. When writing 1 letter, it doesn't include both failures in the output.</p>
  
  <pre><code>import java.util.Scanner;
  public class ValidatePassword {
    public static void main(String[] args) {
      String inputPassword;
      Scanner input = new Scanner(System.in);
      System.out.print("Password: ");
      inputPassword = input.next();
      System.out.println(PassCheck(inputPassword));
      System.out.println("");
    }
  
    public static String PassCheck(String Password) {
      String result = "Valid Password";
      int length = 0;
      int numCount = 0;
      int capCount = 0;
      for (int x = 0; x &lt; Password.length(); x++) {
        if ((Password.charAt(x) &gt;= 47 &amp;&amp; Password.charAt(x) &lt;= 58) || (Password.charAt(x) &gt;= 64 &amp;&amp; Password.charAt(x) &lt;= 91) ||
          (Password.charAt(x) &gt;= 97 &amp;&amp; Password.charAt(x) &lt;= 122)) {
        } else {
          result = "Password Contains Invalid Character!";
        }
        if ((Password.charAt(x) &gt; 47 &amp;&amp; Password.charAt(x) &lt; 58)) {
          numCount++;
        }
        if ((Password.charAt(x) &gt; 64 &amp;&amp; Password.charAt(x) &lt; 91)) {
          capCount++;
        }
        length = (x + 1);
      }
      if (numCount &lt; 2) {
        result = "Not Enough Numbers in Password!";
      }
      if (capCount &lt; 2) {
        result = "Not Enough Capital Letters in Password!";
      }
      if (length &lt; 2) {
        result = "Password is Too Short!";
      }
      return (result);
    }
  }
  </code></pre>