package PatternsQuestions;
import java.util.Scanner;
public class ques20 {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
// setting intial values
int nst = 1;
int nsp = n/2;
int nspbw = 1; // defining space in between
// setting for loop
for(int row = 1; row<=n; row++) {
for (int csp = 1; csp <= nsp; csp++) {
System.out.print(" ");
}
for(int cst=1; cst<=nst; cst++) {
System.out.print("*");
}
int cst;
if(row>=2 && row <n) {
cst = row;
} else {
cst = n+1;
}
for(; cst <= row; cst++) {
for(int cspw=1; cspw<= nspbw; cspw++) {
System.out.print(" ");
}
for(int cst2=1; cst2<= nst; cst2++) {
System.out.print("*");
}
}
//preparation
System.out.println();
if(row < n/2) {
nsp--;
nspbw+=2;
} else {
nsp++;
nspbw-=2;
}
}
scn.close();
}
}
Request you to provide solution for this