Okay so I am getting an error for my code that is trying to count how many of each integer there are in the array. And so im not sure how to fix it. Im getting the error on the while loop at the bottom. Any help would be appreciated. Thanks.
if (ndx != array.length)
while (array[ndx] == array[ndx + 1])
ndx++;
On the last iteration of the outer for loop, ndx is one less than array.length, so when you call array[ndx+1], that is equivalent to array[array.length], which out of bounds, since arrays start indexing at 0. Changing your bottom if statement to:
should do the trick.
It’s also incrementing ndx in the final while loop, so there should be a conditional to check for that, too:
Since you take care of the array.length-1 condition in the while now, you can get rid of the if that had it in the above line.
Hope that helps!