Doubt in star pattern

In que : no. 8 of star pattern , it only works for n= odd cases , not working correctly for n= even cases .
My code is:
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
int star_l = 1;
int star_r = n;

	// row
	int row = 1;
	while (row <= n) {

		// work for columns in row
		for (int csp = 1; csp <= n; csp++) {

			if (csp == star_l || csp == star_r) {
				System.out.print("* ");
			} else {
				System.out.print("  ");
			}

		}

		// prep
		System.out.println();
		if (row <= n / 2) {
			star_l++;
			star_r--;
		} else {
			star_l--;
			star_r++;
		}

		row++;

	}

u have handle it for even no.
e.g n==4

l - - r

  • l r -
  • r l -
  • l r -

left pointer is crossing the right pointer

alternative:
and i think, it can simple to just think as the diagonal of a square
so just print the star at diagonal of square of size n

l . . r
. l r .
. r l .
. l r .

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.