i wrote the code for this pattern it has 9 rows i.e( n=5) using for loop and it is working .
i get it that how it is working for each row except for row no 5, could you tell me how it is working for row no 5 ?
as i think it should print 4 asterisks in row 5 as row no 5 will fall in else block and it should print 9-5=4 asterisks , but instead it is printing 5 asterisk
here is the code
int n = scn.nextInt();
int casp=n*2-1;
for(int i=1; i<=casp;i++) {
if(i<=casp/2) {
for(int j=1;j<=i;j++) {
System.out.print("* ");
}
} else {
for(int k=i;k<=casp;k++) {
System.out.print("* ");
}
}
System.out.println();
}