Question: Question#1. Given the following code [20 pints]: public static void recSequence(int n) { if (n < 0) throw new IllegalArgumentException(); if (n == 5) {
| Question#1. Given the following code [20 pints]: public static void recSequence(int n) { if (n < 0) throw new IllegalArgumentException(); if (n == 5) { System.out.print("|"); } else { System.out.print("a"); recSequence(n - 1); System.out.print("b"); }
} public static void main(String[] args) { recSequence (10); } } a) Consider the above call of the recursive method (recSequence) in the main program, trace the execution of recSequence using the same approach presented in the lectures slides of the Recursion Unit [15 points].
b) Write the final output of the above method [5 points].
please solve part a and part b |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
