'return sum of all items of the array passed that lie in the number range low or high
Trying to understand this question a bit more. Currently I need to return the sum of all the values that lie with a range either low or high within an array. Currently I have got this far (see code below), however I am stuck on what to do next. Any help?
public static int sumrange(int[] data, int low, int high) {
int sum = 0;
if (data == null || data.length == 0) {
return 0;
}
for (int i = 0; i < data.length;) {
if (i < low) {
sum = sum + data[i];
return sum;
}else if (i > high)
sum = sum + data[i];
return sum;
}
return 0;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
