I need to return the greatest negative value, and if there are no negative values, I need to return zero. Here is what I have:
public int greatestNegative(int[]
You just need to think of this problem as 2 steps:
Code:
public int greatestNegative(int[] list) {
int result = 0;
for (int i = 0; i < list.length; i++) {
if (list[i] < 0) {
if (result == 0 || list[i] > result) {
result = list[i];
}
}
}
return result;
}