CJCoding With Joseph
15per day

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
๐Ÿ“ฅ Auto-Input:
5\n
This input is automatically fed to your program's stdin
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.