I want to make a program to output this number sequence: (2),(5),(11),(23),...
where xi = 2*xi-1 + 1, and x0=2.
Here's my code:
public static int num(int n){
if(n <= 0)
return 2;
else
return ((2 * 2)+1);
}
I'm having trouble finding a way to output the numbers 11, 23 and onwards. Would it work if I set a counter variable and continuously loop around the second return statement?
return ((2 * num(n-1))+1);nthere soreturn ((2 * 2) +1);should bereturn ((2 * num(n-1))+1);