In this code if i take n=7 then I'm getting correct output but if i take n=8 or n=10 for even numbers I'm not getting correct output. What should i do to get correct output for even numbers also?

public class P9 {

public static void main(String[] args) {

	
	int n = 8;
	int nsp=n/2;
	int nst=1;
	
	int row=1;
	while(row<=n) {
		
		for(int csp=1; csp<=nsp;csp++) {
			System.out.print("  ");
		}
		for(int cst=1; cst<=nst;cst++) {
			System.out.print("* ");
		}
		for(int csp=1; csp<=nsp;csp++) {
			System.out.print("  ");
		}
		System.out.println();
		if(row<=n/2) {
			nsp--;
			nst+=2;
		}else {
			nsp++;
			nst-=2;
		}
		row++;
			
	}

}

}

hi @LakshmiPrasanna0303
what pattern you want for even numbers

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.