public static void pdi(int n){
if(n<=0){
return;
}
System.out.println(n);
pdi(n-2);
if(n==1){
return;
}
System.out.println(n-1);
i have used this ,can you please guide me through whether I am approaching the concept in a right way
About the another approach
@Adhyayan,
If n=6,
the correct output is:
5
3
1
2
4
6
Your output is:
6
4
2
1
3
5
Your code will give incorrect output for even number because it will print even numbers first and then odd, which is a error.
thank you very much sir
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.