title: Creating a random colour grid with all adjacent colours different
body: <p>So I have the following problem set to me: Write a program that takes an integer command-line argument N, and uses two nested for loops to print an N-by-N board that alternates between 6 colours randomly separated by spaces. The colours are denoted by letters (like 'r' for RED, 'b' for BLUE). You are not allowed to have two of the same colour next to eachother.</p>
  
  <p>So, I know I probably need arrays to get around this problem. I tried several methods that all came up wrong. The following is one of my recent attempts, but I am unsure as how to now go through the grid and correct it. What the code does is make every row randomized with no colour left or right the same, but the columns are not fixed.</p>
  
  <p>Note that I am a first year CS student with no programming history. I am guessing the solution to this problem isnt too complex, however, I cant see a simple solution...</p>
  
  <pre><code>    int N = StdIn.readInt();
      int array1[] = new int[N];
      for (int column = 0; column &lt; N; column++) {
          int x = 0;
  
          for (int row = 0; row &lt; N; row++) {
  
              int c = (int) (Math.random() * 6 + 1);
  
              while (x == c) {
                  c = (int) (Math.random() * 6 + 1);
                  array1[row] = c;
              }
              if (c == 1) {
                  System.out.print("R ");
              }
              if (c == 2) {
                  System.out.print("O ");
              }
              if (c == 3) {
                  System.out.print("Y ");
              }
              if (c == 4) {
                  System.out.print("G ");
              }
              if (c == 5) {
                  System.out.print("B ");
              }
              if (c == 6) {
                  System.out.print("I ");
              }
  
              x = c;
  
          }
  
          System.out.println();
  
      }
  }
  </code></pre>