← Back to Methods
Question 148
Power of Two Using Recursion
Power of Two Using Recursion
Read an integer n (at least 1). Complete thetwoPow(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 oftwoPow(n-1). Call this method from main and print the result.
Expected Output:
32= newline. The output ends with a newline — print one after the last line.
Hints2 available
Sign in to use hintsTopics:
Methods
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · 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.