package PatternsQuestions;
import java.util.Scanner;
public class ques7 {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
int nst=1;
int nsp=0;
int row = 1;
while(row<=n){
// prinitng the first star
for(int cst=1; cst<= nst; cst++) {
System.out.print("*");
}
//setting if statement for space
int csp;
if(row==1 || row==n) {
csp=n+1;
} else {
csp=1;
}
for(; csp<=nsp; csp++) {
System.out.print(" ");
}
int cst2;
if(row==1 || row==n) {
cst2=n-2;
} else {
cst2=0;
}
for(int cst3 =1; cst3<=cst2; cst3++) {
System.out.print("*");
}
for(int cst=1; cst<= nst; cst++) {
System.out.print("*");
}
System.out.println();
if(row==1 || row==n) {
nsp=0;
} else {
nsp=n-2;
}
row++;
}
scn.close();
}
}
I am getting an output like this for n = 5;
**