Doubt in solving this question

I have tried the following code:

public static void sequence(int n){

if(n<=0)
{

return;

}

    System.out.println(n);
    sequence(n-2);//for even

    sequence(n-1); //for odd
    System.out.println(n);

}

But i am not getting the answer . this is the answer

try somehing like:

if(n&1){
       odd(n);
 }
else{ 
     odd(n-1);
}
     even(2,n);

and make separate functions for odd and even

public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();

    for (int i = 1; i <=n ; i++) {
        if(i%2==0)
            PrintIncrease(i);
        else
            PrintDecrease(i);
    }
}
public static void PrintIncrease(int n){
    if(n<=0){
        return;
    }

    PrintIncrease(n-1);
    System.out.println(n);
}

public static void PrintDecrease(int n){
    if(n<=0){
        return;
    }
    System.out.println(n);
    PrintDecrease(n-1);
}

Now i tried something like this but the output is:
6
1
1
2
3
2
1
1
2
3
4
5
4
3
2
1
1
2
3
4
5
6

Process finished with exit code 0

Please give some more hint. I was not able to follow the code you gave.

see this ->

Yes the program ran. But still I am not very clear with the logic. Can you please explain it. According to my understanding if we want to print numbers in increasing sequence then the print statement is written below the recursive call and for decreasing number sequence it is written above the recursive call. But here both the print statements are below the recursive calls. Also can you please explain why even function has taken 2 arguments.

there s no such rule as where to keep the print statement for inc /decreasing order.try to dry run the code by adding some print statements
the 2 arguments were just to limit the even values till n , you can use it by globally defining n nd sing just 1 variable for even too