title: OutOfBounds Exception with 2d Array
body: <p>I'm making a program that finds if there is a letter pair of 2 letters within a line of text, for example, if "AA" was inputted, I would add 1 to alphabet[0][0]. When I try and input "aabbcc" I get this error:</p>
  
  <pre><code>Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 32
          at Freq.processLine(Freq.java:25)
          at Freq.main(Freq.java:12)
  </code></pre>
  
  <p>When I input "AABBCC" I get this 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 Freq.processLine(Freq.java:23)
          at Freq.main(Freq.java:12)
  </code></pre>
  
  <p>I'm not sure why I am getting these errors. Any help would be greatly appreciated. Here is my code:</p>
  
  <pre><code>import java.util.Scanner;
  
  public class Freq{
      private static final int ROWS = 26;
      private static final int COLS = 26;
      private static int[] [] alphabet = new int[ROWS][COLS];
      public static void main(String[] args) {
          String line;
          Scanner userInput = new Scanner(System.in);
          while(userInput.hasNextLine()) {
              line = userInput.nextLine();
              processLine(line);
  
      }
  
  }
  public static void processLine(String line) {
      line.toUpperCase();
      for(int i = 0; i &lt; alphabet.length; i++) {
          for(int j = 0; j &lt; alphabet[i].length; j++) {
              for (int a = 0; a &lt; line.length(); a++) {
                  char firstLetter = line.charAt(a);
                  char secondLetter = line.charAt(a + 1);
                  if (firstLetter == secondLetter) {
                      alphabet[firstLetter - 65][secondLetter - 65] = alphabet[firstLetter - 65][secondLetter - 65] + 1;
                  }
              }
          }
      }
  for (int b = 0; b &lt; alphabet.length; b++) {
      for (int c = 0; c &lt; alphabet[b].length; c++){
          System.out.print(alphabet[b][c] + " ");
          System.out.println();
      }
  }
  }
  }
  </code></pre>