I have done Pattern 17 using WHILE loop and their is error coming DUPLICATE VARIABLE

in video lecture this question is done using FOR loop but i have done it using WHILE loop,but using while loop there is error coming (DUPLICATE VARIABLE)

MY CODE

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

	// * * * - * * *
	// * * - - - * *
	// * - - - - - *
	// - - - - - - -
	// * - - - - - *
	// * * - - - * *
	// * * * - * * *
	//

	// row
	int row = 1;

	// work
	int nst = n / 2;
	int nsp = 1;
	while (row <= n) {

		// work stars
		int cst = 1;
		while (cst <= nst) {
			System.out.print("* ");
			cst++;
		}

		// work spaces
		int csp = 1;
		while (csp <= nsp) {
			System.out.print("- ");
			csp++;
		}

		// work stars

		// int cst=1;                     says duplicate variable
		while (cst <= nst) {
			System.out.print("* ");
			cst++;
		}

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

Hi nipun,since you have already declared cst above so again declaring it is giving you the error duplicate variable error,just write cst=1 and then run your code.

i have corrected my coe by using 2 different cst (cst and cst1)… but can i do my code using while loop with using just one cst

yes you can do it by using ne cst also,only you have to initialize cst=1 when again printing the stars.