// Erika Wolfe // Implements two different sum methods public class Sum { public static void main(String[] args) { System.out.println(sum1(5)); System.out.println(sum2(5)); } // pre: n is non-negative // post: returns the sum of 1 to n inclusive public static int sum1(int n) { int sum = 0; for (int i = 1; i <= n; i++) { sum += i; } return sum; } // pre: n is non-negative // post: returns the sum of 1 to n inclusive public static int sum2(int n) { return n * (n + 1) / 2; } }