Changing for column major ordering in two nested loops simply changes how you calculate the corresponding entry. Effectively, you need to take the row, and add to it the value of the number of total rows * the column in question. Depending on your loop initial position depends if you add one to the row after calculation, or if you subtract one from the column during calculation. I'll do the column.
PHP Code:
public static void printGrid(int iRows, int iCols)
{
StringBuilder sb = new StringBuilder();
for (int r = 1; r <= iRows; ++r)
{
for (int c = 1; c <= iCols; ++c)
{
if (c > 1)
{
sb.append(", ");
}
sb.append((iRows * (c - 1)) + r);
}
sb.append("\n");
}
System.out.println(sb.toString());
}
And simple as that.