title: Locker room question generalized to n people - repeating error
body: <p>I have the following code:</p>
  
  <pre><code>import java.util.Scanner;
  import java.util.Arrays;
  public class Program11 {
  
    public static void main(String args[]) {
      Scanner input = new Scanner(System.in);
      System.out.print("Number of lockers:");
      int number = input.nextInt(); 
      System.out.print("Show stages [y/n]?");
      String show = input.next();
      if(show.equals("y")) 
      {
        for (char[] lockers : getStages(number)) 
        { 
          for (char c : lockers) 
          { 
            System.out.print("" + c); 
          } 
          System.out.println();
        }
      }
    }
  
    public static char[][] getStages(int n){      
      char[] lockers = new char[n];
      char[][] arrayLockers = new char[n][];
      for (int i = 0; i &lt; n; i++) {
        lockers[i] = 'O';
      }
      for (int i = 0; i&lt;1;i++){
        arrayLockers[i] = lockers;
      }
      for(int i = 2; i&lt;=n; i++){
        for(int z = 1; z&lt;n; z++){
          for (int w = i-1; w &lt;= n; w += i){
            lockers[w] = 'X'; 
          }
          arrayLockers[z] = lockers;
        }
  
      }
      return arrayLockers;
    }
  }
  </code></pre>
  
  <p>The output is for n = 10:</p>
  
  <pre><code>&gt; run Program11
  Number of lockers: 10
  Show stages [y/n]? y
  OXXXXXXXXX
  OXXXXXXXXX
  OXXXXXXXXX
  OXXXXXXXXX
  OXXXXXXXXX
  OXXXXXXXXX
  OXXXXXXXXX
  OXXXXXXXXX
  OXXXXXXXXX
  OXXXXXXXXX
  &gt; 
  </code></pre>
  
  <p>The locker room problem goes as follows:
  There are n students and n lockers. The first student opens all the lockers. The second student closes lockers 2,4,6,8,.... the third student closes lockers 3,6,9,12,... This patterns repeats itself until all n students have gone.</p>
  
  <p><strong>My task:</strong></p>
  
  <p>I am supposed to show the lockers at each stage for a given n. 'X' represents closed and 'O' represents open. I am supposed to use arrays only. Clearly this is repeating the same array over and over again which is incorrect. I used the method getStages to return a multi-dimensional array "arrayLockers" to store each stage. 
  Could anyone tell me where I have gone wrong? </p>
  
  <p><strong>Expected output is:</strong></p>
  
  <pre><code>OOOOOOOOOO   
  OXOXOXOXOX   
  OXXXOXXXXX   
  OXXXOXXXXX  
  OXXXXXXXXX  
  OXXXXXXXXX  
  OXXXXXXXXX    
  OXXXXXXXXX   
  OXXXXXXXXX    
  OXXXXXXXXX   
  </code></pre>