Problem In Hollow Diamond

public static void main(String[] args) {

	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int nst = n;
	int nsp = n - 1;

	int row = 1;
	while (row <= n) {
		for (int csp = 1; csp <= nsp; csp++) {
			System.out.print(" ");
		}

		for (int cst = 1; cst <= nst; cst++) {

			System.out.print("*");
		}
		if (row > 1 && row < n) {
			for (int csp = 1; csp <= n - 2; csp++) {
				System.out.print(" ");
			}
			System.out.print("*");
		}

		System.out.println();

		if (row >= 1 && row < n - 1) {
			nst = 1;
		} else {
			nst = n;
		}
		nsp--;
		row++;
	}

}

Please help in this i am not getting the desired output

@amangaur078,
You have to print a hollow diamond, you are printing a hollow rhombus. Is this the correct code you sent?

Sorry, My Bad
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int nsp = 0;
int nst = n;

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

		for (int cst = 1; cst <= nst; cst++) {
			System.out.print("*" + "\t");
			cst++;
		}
		for (int csp = 1; csp <= nsp; csp++) {
			System.out.print(" ");
		}
		for (int cst = 1; cst <= nst; cst++) {
			System.out.print("*" + "\t");
		}

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

	}

this is the code for diamond.

@amangaur078,
initialize nsp by -1 and not 0. Because spaces increase from 1 to 3 to 5 and so on. Similarly decrease by 2.
initialize nst by n/2 + 1 not n.
Remove the extra cst++ in the first for loop.
Add \t with space as well.

In the third for loop add a condition:

			int cst = 1;
			if (row == 1 || row == n)
				cst = 2; // To handle extra Star

			for (; cst <= nst; cst++) {
				System.out.print("*" + "\t");
			}

Finally, remove this condition:

		if (row == 1 && row == n) {
			nst = n;
		} else {

https://ide.codingblocks.com/s/259468 you can refer to this code as well.

got it thank you so much

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.