Hello I am facing some problem in Q12 pattern printing program

I am facing a problem in question no 12 in pattern printing pdf.

@er13aashishgupta_144ebaf32c98e77e Here is my code for the pattern try to benchmark your code with my code.(Look for comments for explaination).

public class Main {
    public static void main(String args[]) {
        int n = 5;
        int nsp = n-1;
        int nst = 1;
        //loop for rows
        for(int i = 1; i <= n; i++){
            //loop for spaces before stars
            for(int j = 1; j <= nsp; j++){
                System.out.print("  ");
            }
            //loop for stars and exclaimation marks
            for(int j = 1; j <= nst; j++){
                //Notice when j is odd we print * but when j is even we print '!'
                if(j%2 != 0){
                    System.out.print("* ");
                }else{
                    System.out.print("! ");
                }
            }
            nsp--;
            nst+=2;
            System.out.println();
        }
    }
}

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.