Section 1 (basics) pattern 20, what should be the condition for inner spaces in pattern

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,for middle spaces you can take a variable msp and see middle spaces are increasing first by 2 and then decreasing by 2 so you can initialize msp by -1 and in preperation work you can increase the msp by 2 if row <=n/2 else decrease by 2.