Challenge - 5 Problems
Call Stack Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 code output
intermediate2:00remaining
What is the output of this recursive call stack?
Consider the following Java code that uses recursion. What will be printed when countdown(3) is called?
Java
public class Test { public static void countdown(int n) { if (n == 0) { System.out.println("Done"); return; } System.out.println(n); countdown(n - 1); } public static void main(String[] args) { countdown(3); } }
Attempts:
2 left
💻 code output
intermediate2:00remaining
What is the value of variable after nested method calls?
Given the following Java code, what is the value of result after main finishes?
Java
public class Test { public static int addOne(int x) { return x + 1; } public static int doubleIt(int x) { return x * 2; } public static void main(String[] args) { int result = doubleIt(addOne(3)); System.out.println(result); } }
Attempts:
2 left
💻 code output
advanced2:30remaining
What is printed by this mutual recursion example?
Examine the following Java code with two mutually recursive methods. What is the output when foo(2) is called?
Java
public class Test { public static void foo(int n) { System.out.println("foo " + n); if (n == 0) { System.out.println("foo done"); return; } bar(n - 1); } public static void bar(int n) { if (n == 0) { System.out.println("bar done"); return; } System.out.println("bar " + n); foo(n / 2); } public static void main(String[] args) { foo(2); } }
Attempts:
2 left
🔧 debug
advanced1:30remaining
What error does this recursive method cause?
Consider this Java method that calls itself without a base case. What error will occur when infiniteRecursion() is called?
Java
public class Test { public static void infiniteRecursion() { infiniteRecursion(); } public static void main(String[] args) { infiniteRecursion(); } }
Attempts:
2 left
🧠 conceptual
expert2:00remaining
How many stack frames are created during this recursive factorial call?
Given the following factorial method, how many stack frames are created when factorial(5) is called?
Java
public class Test { public static int factorial(int n) { if (n <= 1) return 1; return n * factorial(n - 1); } public static void main(String[] args) { int result = factorial(5); System.out.println(result); } }
Attempts:
2 left
