I would write it like this:
class MDArrays { private static final int ROWS; private static final int COLS; private static final int START_VALUE; private static final int INC_VALUE; static { ROWS = 2; COLS = 3; START_VALUE = 2; INC_VALUE = 2; } public static void main(String[] args) { final int[][] x; int t; x = new int[ROWS][COLS]; t = START_VALUE; for(int row = 0; row < x.length; row++) { for(int col = 0; col < x[row].length; col++) { x[row][col] = t; t += INC_VALUE; System.out.println(x[row][col]); } } } }
The major difference is that I use the .length member rather than hard coded values. That way if I change it to x = new int[3][2]; then the code magically works and stays within its bounds.
The other big difference is that I use row/col instead of i/j. i/j are fine (and traditional) but I find when dealing with arrays of arrays (Java doesn't actually have multi-dimensional arrays) that it is easier to keep track of things if I use the more meaningful row/col (helps prevent you from doing things like for(int col = 0; row < x.length; col++)... which, incidentally, is the bug you have.