Q8) How to remove the extra star from the middle row?

public static void main(String[] args) {

	Scanner sc=new Scanner(System.in);
	int n=sc.nextInt();
	int i=1,nst=1,ns=n-2,nS=0;
	while(i<=n) {
		int cS=1;
		while(cS<=nS) {
			System.out.print(" ");
			cS++;
		}
		int cst=1;
		while(cst<=nst) {
			System.out.print("*");
			cst++;
		}
		int cs=1;
		while(cs<=ns) {
			System.out.print(" ");
			cs++;
		}
		int csT=1;
		while(csT<=nst) {
			System.out.print("*");
			csT++;
		}
		if(i<=n/2) {
			ns=ns-2;
			nS++;
		}
		else {
			ns=ns+2;
			nS--;
		}
		i++;
		System.out.println();
	}
}

}

@laibaahsan27_1dfa992390072fd9 Add this condition to your second while loop used for printing stars after spaces.
While loop will look like this :

while(csT<=nst) {
            if(i == (n/2)+1)
            break;
			System.out.print("*");
			csT++;
		}

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.