title: How do you print rows and columns in a 2-d array?
body: <p>I'm trying to get this array to display 4 values arranged in a 2x2 array. With what I'm doing so far, I'm getting an array out of bounds error. How can I do this display properly?</p>
  
  <pre><code>import java.util.Scanner;
  import java.util.Random;
  
  
  
   public class GridPractice
  {
  
  public static void main(String[] args)
  {
    //declarations
    Scanner in = new Scanner(System.in);
    Random  generator = new Random();
    int [][] grid;    //un-instantiated grid
    int size = 0; //number of rows and columns
  
    //get size of grid - no validation &amp; instantiate
    System.out.print("Enter size of grid: ");
    size = in.nextInt();
    grid = new int[size][size];
  
     //fill grid with random number from 1..99
    System.out.println();
    for (int row=0; row&lt;size; row++)
    {
       for (int col=0; col&lt;size; col++)
       {
          grid[row][col] = generator.nextInt(100); //random numbers 0.99 - not 100
  
       }
  
     }
  
    System.out.printf("%2d\n", grid[size][size]); 
  </code></pre>