Java - Methods and Code Reusability
Consider this method:
What is wrong with this method if the goal is to return the sum of all positive numbers?
public static int sumPositive(int[] numbers) {
int sum = 0;
for (int n : numbers) {
if (n > 0) return sum + n;
}
return sum;
}What is wrong with this method if the goal is to return the sum of all positive numbers?
