Return to List## Solve: Array Range Sum

### Related Lessons

Created By: Geoffrey Challen

/ Version: `2022.1.0`

Write a method named `arrayRangeSum`

.
It receives an `int[]`

and a positive `int`

`range`

as parameters.
You should return the sum of all the elements in the array that are between `range`

and `range`

* -1, non-inclusive.

For example, given the array `{1, -4, 2, 24, -124}`

and the range `8`

, you would return `-1`

: `1 + -4 + 2`

, since
these are the values in the array strictly greater than `-8`

and strictly less than `8`

.
Given the range `124`

, you should return `23`

: `1 + -4 + 2 + 24`

, since these are the values in the array strictly
greater than `-124`

and less than `124`

.

Note that this problem is a great fit for the enhanced `for`

loop!

Stuck? You may find these lessons helpful: