In the Sum class, write Java code for recursive and iterative versions of methods to calculate
Posted: Mon Jul 11, 2022 9:55 am
<Recursive and Iterative> In the Sum class, write Java code for recursive and iterative versions of methods to calculate the summation of all the numbers from n down to 1. For example, if n is 1, the method returns 1, if n is 5, the method returns 15. public class Sum { public static void main(String[] args) { int n = 5; System.out.println("Sum System.out.println("Sum Iterative Recursive = = } // Sum Recursive Version public static int sumRecursive (int n) // ADD YOUR CODE HERE } // Sum Iterative Version public static int sumIterative (int n) // ADD YOUR CODE HERE } /* OUTPUT Sum Recursive = 15 Sum Iterative = 15 "+sumRecursive (n)); + sumIterative (n)); { { a) Write Java code of recursive version of the method sumRecursive. b) Write Java code of recursive version of the method sumIterative.