This is an exercise in the Nyhoff book. I am trying to figure out how to output to the consul the column position and the row position 5 times. So that it reads like this:
column: random number, row: random number
column: random number, row: random number
column: random number, row: random number
column: random number, row: random number
column: random number, row: random number
Instead of getting the random number in the array, I am getting the array location. How do I access the individual random numbers?
size (150, 200);
int [] columns = new int[5];
int [] rows = new int[5];
for (int i = 0; i < columns.length; i++)
{
columns [i] = int (random(0, width));
printArray (columns[i]);
}
for (int j = 0; j < rows.length; j++)
{
rows [j] = int (random(0, height));
printArray (rows[j]);
}
for (int k = 0; k < rows.length; k++)
{
println ("columns: " + columns + "," + "rows: " + rows);
}
Yes, at one point I thought to try solving this using 2D array approach. However, because this exercise follows their (the Nyhoffs’) chapter on 1D arrays I wanted to make sure I could do that via 1D as theoretically it’s a simpler structure… (though still it kicked my butt…)