Not able to submit anycode

I’m always getting test case fail for negative number , even I copied and paste by unlocking editorial , its not submitting the code ,

I want to submit the code for another pattern but not able to do anything.

Here’s my code for Pattern InvertedHourGlass , can some one help me please ?

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
    // write your code here
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    p3(n);
}

public static void p3(int n) {
    int myLenth = 2 * n + 1;
    int nst = 0;
    int space = myLenth - 2;
    int secVal = n;
    for (int i = 1; i <= myLenth; i++) {
        int myN = n;
        for (int j = 0; j <= nst; j++) {
            System.out.printf(" %d ", myN);
            myN--;
        }

        for (int j = 1; j <= space; j++) {
            System.out.printf("   ", space);
        }


        myN = secVal;
        //nst - 1 is to print 1 less column
        for (int j = 0; j <= (j == n ? nst - 1 : nst); j++) {
            System.out.printf(" %d ", myN);
            myN++;
        }


        System.out.println();
        if (i <= myLenth / 2) {
            nst += 1;
            space -= 2;
            if (i != n) {
                secVal--;
            }
        } else {
            nst -= 1;
            space += 2;
            if (i != n + 1) {
                secVal++;
            }
        }
    }
}

}

Hey @vivek4988_7c34775e05f479ae As I can see I have tried to submit the same code of yours and there is no issue in submitting but you answer is wrong thats why your test cases are getting failed.
Instead of using printf statement you should use print statement with a single space bcoz your output should be exactly same as sample output (not even single space can be misplaced).

Yes this worked , thanks

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.