Section: 1 (basics) Pattern 19

i did not understand how to correct the 1st and last row in this pattern.

my code:

Scanner s = new Scanner(System.in);
int n = s.nextInt();

	// row
	int row = 1;

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

}

Hii Nipun,
Initialize nst with n/2 + 1
and inside while loop before second for loop for star check if the row is equal to one or equal to n, if the condition evaluates to be true then initialize cst with 2 else initialize cst with 1.
see for example n = 7, then nst = 4. For 1st row 1st for loop will print 4 stars and since nsp = -1 so no spaces will be printed and since the row == 1 then the condition will evaluated to be true so the cst = 2, so only three stars will be printed.

okay…thanks now my code is working properly