I have a small question. I'm working with recursion. I need to write a method with one positive integer parameter called n. The method will write 2 n -1 integers.
and it's working, except i'm missing pattern that i need.
that's my code:
public static String printExpo(int n) {
if(n == 1)
return "3";
else {
String str = printExpo(n-1);
return str +" "+ (n+3) +" "+ str ;
}
}
It's working. and that's my output
enter :1
3
enter : 2
3 5 3
but when i'm input number 3 and so on..
enter :3
3 5 3 6 3 5 3
what i'm missing ?
That's the output i wish to have.
n=1: Output is: 3
n=2: Output is: 3 5 3
n=3: Output is: 3 5 3 7 3 5 3
n=4: Output is: 3 5 3 7 3 5 3 9 3 5 3 7 3 5 3
Could anyone give any hint? Thanks in advance

New Topic/Question
Reply



MultiQuote




|