mattiepanda
New Member
\[code\]public class FindSum{private static int sum(int n){if (n==1)return 1;elsereturn n + sum (n-1);}public static int getSum(int n){if (n>0)return sum(n);else{throw new IllegalArgumentException("Error: n must be positive");}}}\[/code\]According to my book, this tests that n>0 before execution. I don't understand why that would be the case if the test "if (n>0)" comes after the algorithm. Shouldn't the two methods be flipped in order to accomplish this test?