Write a recursive mathematical definition for computing 2 lifted to power n for a positive integer n | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Write a recursive mathematical definition for computing 2 lifted to power n for a positive integer n

help me to solve this

21st Mar 2021, 6:09 PM
Habo Osman
10 Answers
+ 5
Please share your attempt while seeking help. All we want to see is whether you tried or not.
21st Mar 2021, 6:19 PM
Avinesh
Avinesh - avatar
+ 2
thx a lot Martin Taylor 🖤 you just helped me with the next problem 😂🖤
22nd Mar 2021, 3:25 AM
Habo Osman
+ 1
I think that's lifted and not lefted. Probably a power method is all he looking for.
21st Mar 2021, 6:28 PM
Avinesh
Avinesh - avatar
+ 1
import java.util.Scanner ; public class TestMax{ public static void main(String[] args) { Scanner input = new Scanner (System.in ); System.out.println("Enter a non negative number to be the power of 2" ); int power = input.nextInt (); System.out.println ("result = " + xMethod (power)) ; } public static int xMethod(int power) { if (power < 0) return 0 ; else return 2*xMethod(power-1); } }
21st Mar 2021, 6:55 PM
Habo Osman
+ 1
that's the last code i tried it.. hope you get what i mean
21st Mar 2021, 6:56 PM
Habo Osman
21st Mar 2021, 7:03 PM
Habo Osman
+ 1
it finally worked correctly thank you so much Avinesh I've been working on it for hours 😭
21st Mar 2021, 7:10 PM
Habo Osman
0
Just return 1 instead of 0.
21st Mar 2021, 7:07 PM
Avinesh
Avinesh - avatar
0
Habo Osman you're welcome
21st Mar 2021, 7:15 PM
Avinesh
Avinesh - avatar
0
"Write a recursive mathematical definition...“ I‘m not sure why you all are writing code? That does not seem to be what‘s asked. a_0 = 1 a_n = 2*a_{n-1} , n>=1
22nd Mar 2021, 5:22 AM
John Doe