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

**URL:** https://discourse.processing.org/t/how-to-check-for-similar-number-in-array-and-bring-out-a-error-sign/24454
**Category:** Beginners
**Tags:** homework
**Created:** [October 8, 2020, 10:24pm UTC](https://discourse.processing.org/t/how-to-check-for-similar-number-in-array-and-bring-out-a-error-sign/24454 "2020-10-08T22:24:08Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![newtothis](https://avatars.discourse-cdn.com/v4/letter/n/7ba0ec/32.png) [@newtothis](https://discourse.processing.org/u/newtothis)
#### Post date: [October 8, 2020, 10:24pm UTC](https://discourse.processing.org/t/how-to-check-for-similar-number-in-array-and-bring-out-a-error-sign/24454/1 "2020-10-08T22:24:08Z")

</div>

> please format code with \</\> button \* [homework policy](https://discourse.processing.org/faq/#homework) \* [asking questions](https://discourse.processing.org/t/2147)

```auto
       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 ?

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [October 8, 2020, 10:41pm UTC](https://discourse.processing.org/t/how-to-check-for-similar-number-in-array-and-bring-out-a-error-sign/24454/2 "2020-10-08T22:41:52Z")

</div>

> [@newtothis](#):
>
> i’m getting “array index out bound expectation 6” error

In which line does it occur?

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [October 8, 2020, 10:46pm UTC](https://discourse.processing.org/t/how-to-check-for-similar-number-in-array-and-bring-out-a-error-sign/24454/4 "2020-10-08T22:46:17Z")

</div>

> [@newtothis](#):
>
> ` for(int iIndex=0;iIndex<6;`

Try \< 5

How did you declare the array?

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [October 8, 2020, 10:46pm UTC](https://discourse.processing.org/t/how-to-check-for-similar-number-in-array-and-bring-out-a-error-sign/24454/5 "2020-10-08T22:46:55Z")

</div>

> [@newtothis](#):
>
> `while (iNext < 6 ) {`

Or try \< 5 here

Chrisir

---

<div class="post-metadata">

### Author: ![newtothis](https://avatars.discourse-cdn.com/v4/letter/n/7ba0ec/32.png) [@newtothis](https://discourse.processing.org/u/newtothis)
#### Post date: [October 8, 2020, 10:48pm UTC](https://discourse.processing.org/t/how-to-check-for-similar-number-in-array-and-bring-out-a-error-sign/24454/6 "2020-10-08T22:48:46Z")

</div>

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

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

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [October 8, 2020, 10:51pm UTC](https://discourse.processing.org/t/how-to-check-for-similar-number-in-array-and-bring-out-a-error-sign/24454/7 "2020-10-08T22:51:59Z")

</div>

6 means from 0 to 5

> [@newtothis](#):
>
> `for(int iIndex=0;iIndex<6; `

\<4

---

<div class="post-metadata">

### Author: ![newtothis](https://avatars.discourse-cdn.com/v4/letter/n/7ba0ec/32.png) [@newtothis](https://discourse.processing.org/u/newtothis)
#### Post date: [October 8, 2020, 10:59pm UTC](https://discourse.processing.org/t/how-to-check-for-similar-number-in-array-and-bring-out-a-error-sign/24454/8 "2020-10-08T22:59:10Z")

</div>

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
