Section 1 (basics) star pattern 20

i am not getting the logic how to print middle spaces and stars on the edges

my code;

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

	// Ques 20:
	// n = 7
	// - - - *
	// - - * - *
	// - * - - - *
	// * - - - - - *
	// - * - - - *
	// - - * - *
	// - - - *

	// row
	int row = 1;

	// work

	int nst = 1;
	int nsp = n / 2;

	while (row <= n) {

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

	}

Hi nipun
I have made the required changes to your code.

Hope it helps.

import java.util.*;

class Main {
public static void main(String[] args) {

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

	// Ques 20:
	// n = 7
	// - - - *
	// - - * - *
	// - * - - - *
	// * - - - - - *
	// - * - - - *
	// - - * - *
	// - - - *

	// row
	int row = 1;

	// work

	int nst = 1;
	int nsp = n / 2;

	while (row <= n) {

		// work space
		int csp = 1;
		while (csp <= nsp) {
			System.out.print("- ");
			csp++;
		}
		// work stars
		int cst = 1;
		while (cst <= nst) {
			if(cst == 1 || cst == nst) {
				System.out.print("* ");
			}else {
				System.out.print("- ");
			}
			
			cst++;
		}

		// preparation

		if (row <= n / 2) {
			nsp--;
			nst = nst + 2;
		} else {
			nsp++;
			nst = nst - 2;
		}
		
		System.out.println();
		row++;

	}

}

}

thankyou. now i understand the logic