Ganesh's pattern

my code pass one test case that is other test cases…which my code does not pass…also give me the right code

Scanner sc = new Scanner(System.in);
int n= sc.nextInt();
if(n>=5 && n<= 99 && n%2!=0)
{
int nsp = n-5;
for(int row =1 ; row<=n ;row++)
{

		if(row>(n/2)+1 && row<n)
		{
			System.out.print(" ");
		}
		else
		{
		System.out.print("*");
		}

// work for spaces
for(int csp =1;csp<=nsp;csp++)
{
if(row != (n/2)+1 && row!=n)
{
System.out.print(" ā€œ);
}
else
{
System.out.print(ā€*");
}
}

// work for stars
System.out.print("");
// work for soace sand stars
for(int csp=1;csp<=nsp;csp++)
{
if(row!=1 && row != (n/2)+1)
{
System.out.print(" ā€œ);
}
else
{
System.out.print(ā€
");
}
}
// again work for starts and spaces
if(row>1 && row<=n/2)
{
System.out.print(" ā€œ);
}
else
{
System.out.print(ā€*");
}
System.out.println();
}
}

@mayanktiwari6957,
Input:
5
Expected Output:

* ***
* *
*****
  * *
*** *

Your output:

***
** 
***
 **
***

https://ide.codingblocks.com/s/254572 correct code

this is only number (i.e 5)for which my code is big running

@mayanktiwari6957,
If the input is 9 then too your code is printing the wrong output buddy

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.