How to check for similar number in array and bring out a error sign

please format code with </> button * homework policy * asking questions

       for(int iIndex=0;iIndex<6; iIndex++) {                               
                fill(67, 214, 250);
                text(iArray[iIndex], (125 + 100 * iIndex), 200);
                
                
                int iNext= iIndex+1;
                while (iNext < 6 ) {
                    fill(255, 0, 0);
                    if (iArray[iIndex] == iArray[iNext]) {         // getting a error here
                        text("ERROR, match between number " + (iIndex + 1) + " and " + (iNext + 1), 100.0,(400 + iCount * 30));
                        ++iCount;
                        
                    }
                    
                    ++iNext;
                }
                
            
        }

I’m using random function to store number in the array and the output has to be shown on the window , but when there is 2 similar numbers i have to show a error message.
That where I’m stuck right now because i’m getting “array index out bound expectation 6” error. So what condition i am suppose to put in while function ?

In which line does it occur?

Try < 5

How did you declare the array?

Or try < 5 here

Chrisir

this how i declare int[] iArray = new int[6];

i already tried 5 before but it’s still the same problem

6 means from 0 to 5

<4

i have decreased the number each time going from 6 to 2 im getting a error message, however when i go to <1, there is no "array index out bound expectation 6” but the error text message im suppose to show is not coming on the window

1 Like