โ Back to Methods
Question 148
Power of Two Using Recursion
Power of Two Using Recursion
Read an integer n (at least 1). Complete the twoPow(int n) method to calculate 2^n using recursion (no loops allowed). The base case is when n equals 1 (return 2). For other values, multiply 2 by the result of twoPow(n-1). Call this method from main and print the result.
Expected Output:
32
Topics:
Methods
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (sysout, psvm, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.