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