Question: Exercise: Determine the output of the following java code: public class MyClass { public static void main(String args[]) { System.out.println(recursive function = + func(4));
Exercise: Determine the output of the following java code: public class MyClass { public static void main(String args[]) { System.out.println("recursive function = " + func(4)); } public static int func(int val){ if (val == 0) // base case return (val + 6); else return 8 + func(val-1); // recursive call } } NB: If you did this correctly stepwise: final output is 38 NB: Try and work it out manually and then compile on a machine
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
