I have a 2D array. I assign it likt this int populations[][] = new int [300][1];
. I would like to assign 1 random value (from 0 - 4) into the each row of 300. This what I got so far.
private void test(){
for (int i = 0; i < 300; i++){
for(int j = 0; j < 1; j++){
populations[i][j] = random.nextInt(4);
}
}
System.out.println(populations.length);
System.out.println(Arrays.deepToString(populations));
}
However, I got an Array Index out of Bounds Exception of 300. How could I fix that?