In patternQuesPdf question number: 8, I wrote the code and it is working perfectly fine for input 5, but when I try to test the code for input 7 I am getting the wrong output.
Can anyone please solve the issues.
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc= new Scanner(System.in);
int n=sc.nextInt();
int row=1, nst=1, nsp1=0, nsp2=n/2+1;
while(row<=n){
for(int csp=1; csp<=nsp1; csp++)
System.out.print(" \t");
for(int cst=1; cst<=nst; cst++)
System.out.print("*\t");
for(int csp=1; csp<=nsp2; csp++)
System.out.print(" \t");
for(int cst=1; cst<=nst; cst++){
if(row!=n/2+1)
System.out.print("*\t");
}
System.out.println();
if(row<=n/2){
nsp1++;
nsp2-=2;
}else
{
nsp1--;
nsp2+=2;
}
row++;
}
}
}
