Question 8. How to make code work when n is even?

package new_pattern_practice;

import java.util.Scanner;

public class ques8 {

public static void main(String[] args) {
	// TODO Auto-generated method stub
	Scanner scn = new Scanner(System.in);
	int n = scn.nextInt();
	
	//initializing variables
	
	int nsp=n-2;
	int nsp2=0;
	
	for(int rows=1; rows<=n; rows++) {
		for(int csp2=1; csp2<=nsp2; csp2++) {
			System.out.print(' ');
		}
		
		System.out.print('*');
		
		for(int csp=1; csp<=nsp;csp++) {
			System.out.print(' ');
		}
		
		
		
		if(n%2==0 && rows!=n/2) {
		System.out.print('*');
		}
		
		if(n%2!=0 && rows!=(n+1)/2) {
			System.out.print('*');
		}
		//prep
		System.out.println();
		if(rows<=n/2) {
			nsp-=2;
			nsp2+=1;
		} else {
			nsp+=2;
			nsp2-=1;
		}
	}
	
	
	
	
	
	scn.close();
}

}

It works if n is odd (5 in the question) but can’t get it to work if n is even.

@sinuscoupon0s_4659768f9d9b587e This pattern is only designed for Odd no. Its not possible to give the same symmetry for even numbers. So Just do it for odd numbers.

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.