able to solve it but not working for N>=5 other than 7 need an approach to solve this
package challenges;
import java.util.Scanner;
public class Ganeshpattern {
public static void main(String[] args) {
{
Scanner scan =new Scanner(System.in);
int N=scan.nextInt();
int row=1;
int nst=1;
int nsp=(N+1)/4;
int nst1=(N+1)/2;
int nsp1=(N+1)/4;
while(row<=N)
{
if(row>=1&&row<=(N+1)/2)
{
for(int cst=1;cst<=nst;cst++)
{
System.out.print("*");
}
for(int csp=1;csp<=nsp;csp++)
{
System.out.print(" ");
}
for(int cst1=1;cst1<=nst1;cst1++)
{
System.out.print("*");
}
}
if(row==(N+1)/2+1||row==(N+1)/2+2)
{
for(int csp=1;csp<=nsp;csp++)
{
System.out.print(" ");
}
for(int cst=1;cst<=nst;cst++)
{
System.out.print("*");
}
for(int csp1=1;csp1<=nsp1;csp1++)
{
System.out.print(" ");
}
for(int cst=1;cst<=nst;cst++)
{
System.out.print("*");
}
}
if(row==N)
{
for(int cst1=1;cst1<=nst1;cst1++)
{
System.out.print("*");
}
for(int csp1=1;csp1<=nsp1;csp1++)
{
System.out.print(" ");
}
for(int cst=1;cst<=nst;cst++)
{
System.out.print("*");
}
}
System.out.println();
if(row==1)
{
nst1=nst1-3;
}
if(row==N/2)
{
nsp=nsp-2;
//nsp=0
//nst1=4
//nst=3
nst1=nst1+3;
nst=nst+2;
}
if(row==(N+1)/2)
{
nsp=nsp+3;
//nsp=3
//nst=1
//nsp1=2
nst=nst-2;
}
row++;
}
}
}
}