# Java's for each loop

**URL:** <https://forum.devtalk.com/t/javas-for-each-loop/105241>\
**Category:** General Dev Chat\
**Tags:** java\
**Created:** [16 April 2023 23:31 UTC](https://forum.devtalk.com/t/javas-for-each-loop/105241 "2023-04-16T23:31:56Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![finner](https://forum.devtalk.com/letter_avatar_proxy/v4/letter/f/a4c791/32.png) [@finner](https://forum.devtalk.com/u/finner)\
**Post date:** [18 April 2023 08:40 UTC](https://forum.devtalk.com/t/javas-for-each-loop/105241/4 "2023-04-18T08:40:00Z")

</div>

hi @harwind -  
According to the code you have pasted when you pass `1` into the method `hasApplicationNumber` an `IllegalArgumentException` will be thrown. So the test should fail.  
I’ve also noticed that you are using `double` in the `ApplicationData` class but treating them as `int` in the `hasApplicationNumber` method.  
Here is a stripped down version without the `ApplicationData` class and using `int`.

```java
public class DevTalkTest {

    private final int[] numbers = new int[]{9, 7, 400};

    @Test
    public void shouldHaveApplicationNumber1() {
        assertTrue(hasApplicationNumber(1));
    }

    public boolean hasApplicationNumber(int number) {
        if (number <= 3) {
            throw new IllegalArgumentException("bad number");
        }
        for (int num : numbers) {
            if (num == number) return true;
        }
        return false;
    }

}

```

The tests will fail with the error:

```java
bad number
java.lang.IllegalArgumentException: bad number
. . . 

```

---

_[View the full topic](https://forum.devtalk.com/t/javas-for-each-loop/105241)._
