I have a 2 dimensional 9 x 9 array (twoArray) that is filled with numbers between 1 & 17.
I am trying to create a one dimensional array (oneArray) that will provide me with the occurrence of the numbers in twoArray.
i.e. if the number ‘1’ appears ‘3’ times in the twoArray, then the value in oneArray[0] will be ‘3’, the number ‘15’ once, then oneArray[14] will be ‘1’, etc. I have the following code that I have written, but I am getting a ‘ArrayIndexOutOfBoundsException’
Not sure if my code is even correct for accomplishing this. Any guidance would be appreciated. I am not looking for the answer, just some advice so I can do it myself.
int[] oneArray= new int[17];
for (int i= 0; i< twoArray.length; i++)
{
for (int j= 0; j< twoArray[j].length; j++) **// exception occurs here**
{
int num = 0;
num = twoArray[i][j] - 1;
oneArray[num] += 1;
}
}