i have a doubt in pattern 17 of the assignment
for odd no. the code is running fine but for even number its not working properly
heres the code
import java.util.Scanner;
public class Pattern17 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number: ");
int n = sc.nextInt();
int rows = 1;
int nst = n / 2;
int nsp = 1;
while (rows <= n) {
for (int cst = 1; cst <= nst; cst++) {
System.out.print("*");
}
for (int csp = 1; csp <= nsp; csp++) {
System.out.print(" ");
}
for (int cst = 1; cst <= nst; cst++) {
System.out.print("*");
}
System.out.println();
rows++;
if (rows > n / 2 + 1) {
nst++;
nsp = nsp - 2;
} else {
nst--;
nsp = nsp + 2;
}
}
sc.close();
}
}