package Patterns;
import java.util.Scanner;
public class Pattern17 {
public static void main(String[] args) {
	Scanner scn = new Scanner(System.in);
	int n = scn.nextInt();
	// defining the number of stars and spaces
	int nst = n / 2;
	int nsp = 1;
	int row = 1;
	// defining the while function
	while (row <= n) {
		
		// setting the cst 
		int cst = 1;
		while (cst <= nst) {
			System.out.print("*");
			cst += 1;
		}
		// setting the csp
		int csp = 1;
		while (csp <= nsp) {
			System.out.print(" ");
			csp += 1;
		}
		// defining other cst variable as the output
		// in the console was not showing if i used
		// the previous cst function
		int cst2 = 1;
		while (cst2 <= nst) {
			System.out.print("*");
			cst2 += 1;
		}
		System.out.println();
		if (row < n / 2) {
			nst -= 1;
			nsp += 2;
		} else {
			nst += 1;
			nsp -= 2;
		}
		row += 1;
	}
	scn.close();
}
}
I did this using a while function. The console out put for n = 9 is like this:
- 
*
I am thinking that another else if (row==n/2) could be added but I dont know how to go around it
