title: Java - StringIndexOutOfBoundsException
body: <p>First of all, here is the problematic part of my code; these are very basic classes</p>
  
  <pre><code>public Passenger(String Name, String adress, String number, String password){
      count++;
      accId+=count;
  
      this.Name=Name;
  
      this.adress=adress;
      this.number=number;
  
      if(checkPw(password)==true){
          this.password=password;
      }
  
  }
  
  private boolean checkPw(String password){
      int length;
      length = password.length();
  
      if(length != 6){
          return false;
      }
      else if(password.charAt(0)==0){
          return false;
      }
      else {
          for (int i = 0; i &lt; password.length();i++){
              if((password.charAt(i))==(password.charAt(i+1))){
                  return false;
              }
          }
      }
      return true;        
  }
  </code></pre>
  
  <p>testClass:</p>
  
  <pre><code>public static void main(String[] args){
      Passenger gokhan=new Passenger("Gokhan","Istanbul","xxx","254651");
  
      System.out.println(gokhan.password);
  }
  </code></pre>
  
  <p>So, I think the problem is in the Passenger class. Its my first time that class in class things (I meant the if(checkPw(password)==true) part). In the test class, it looks very clear and I never thought that this error will appear. How can I avoid this message?</p>
  
  <p>Full error:</p>
  
  <pre><code>Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 6
      at java.lang.String.charAt(String.java:658)
      at project1.Passenger.checkPw(Passenger.java:45)
      at project1.Passenger.&lt;init&gt;(Passenger.java:27)
      at project1.testClass.main(testClass.java:11)
  </code></pre>
  
  <p>Java Result: 1</p>