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++;
}