title: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3 when adding objects of array
body: <p>I need to do a program with a method that receives a two dimensional 3*3 array with the information of several Professors (created in a class called "Professor") and gets the amount of hours they work, how much money they make per hour and add them up to a variable that returns the total amount that's paid to the professors. I've already created the classes, the array, the objects with the information using the constructor, and put each object in every index of the array.
  However, when I loop through the array I always get this error message as output: </p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3</p>
  </blockquote>
  
  <p>Here's my code (The last two numbers on the objects are (in order) the amount of hours the professor works, and the money they make per hour. I created all the objects with the same information for testing purposes, so 8 would be the hours and 1.66 the amount of money:
  </p>
  
  <pre><code>public static void main(String[] args) {
      // TODO code application logic here
      Scanner in = new Scanner(System.in);
  
      Profesor arreglo[][];
      arreglo = new Profesor[3][3];
  
      Profesor profe1 = new Profesor(126509404, "Edgar", "Hernandez", 29, "M", 8, 1.66);
      Profesor profe2 = new Profesor(233849920, "Nuria", "Ramírez", 52, "F", 4, 2.84);
      Profesor profe3 = new Profesor(126509404, "Edgar", "Hernandez", 29, "M", 8, 1.66);
      Profesor profe4 = new Profesor(126509404, "Edgar", "Hernandez", 29, "M", 8, 1.66);
      Profesor profe5 = new Profesor(126509404, "Edgar", "Hernandez", 29, "M", 8, 1.66);
      Profesor profe6 = new Profesor(126509404, "Edgar", "Hernandez", 29, "M", 8, 1.66);
      Profesor profe7 = new Profesor(126509404, "Edgar", "Hernandez", 29, "M", 8, 1.66);
      Profesor profe8 = new Profesor(126509404, "Edgar", "Hernandez", 29, "M", 8, 1.66);
      Profesor profe9 = new Profesor(126509404, "Edgar", "Hernandez", 29, "M", 8, 1.66);
  
      arreglo[0][0] = profe1;
      arreglo[0][1] = profe2;
      arreglo[0][2] = profe3;
  
      arreglo[1][0] = profe4;
      arreglo[1][1] = profe5;
      arreglo[1][2] = profe6;
  
      arreglo[2][0] = profe7;
      arreglo[2][1] = profe8;
      arreglo[2][3] = profe9;
  
  
      System.out.println("La suma de los salarios es: " +sumaSalarios(arreglo));
  
  
  
  }
  
  public static double sumaSalarios(Profesor matriz[][]) {
      int sumaHoras = 0;
      double sumaValorHoras = 0;
      double salarios = 0;
      for (int i = 0; i &lt; matriz.length; i++) {
          for (int j = 0; j &lt; matriz.length; j++) {
              sumaHoras = sumaHoras + matriz[i][j].getHoras();
          }
      }
  
      for (int i = 0; i &lt; matriz.length; i++) {
          for (int j = 0; j &lt; matriz.length; j++) {
              sumaValorHoras = sumaValorHoras + matriz[i][j].getValorHora();
          }
      }
  
      return salarios = sumaHoras*sumaValorHoras;
  
  }
  </code></pre>