Respected sir/mam ,I am stuck in q 19 of pattern assignment, the code that i am providing you is working perfectly in eclipse , but it took a lot of time for me to think and code it, and at the end I did it with some jugaad for printing spaces , so I just want you to check whether that code is acceptable or is there any other way to code it.
package sec;
import java.util.Scanner;
public class paattern22 {
public static void main(String[] args) {
System.out.println("Enter the value of n ");
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
int nst = 4;
int nsp = 0;
int rows = 1;
while (rows <= n) {
int cst = 1;
while (cst <= nst) {
System.out.print("*");
cst++;
}
int csp = 1;
while (csp <= nsp) {
System.out.print(" ");
csp++;
}
if(rows>2&&rows<n-1) {
System.out.print(" ");
}
if(rows==(n+1)/2) {
System.out.print(" ");
}
for (cst = 1; cst <= nst; cst++) {
if (cst == 4) {
System.out.print(" ");
} else {
System.out.print("*");
}
}
System.out.println();
if (rows <= n / 2) {
nst--;
nsp+=1;
}
else {
nst++;
nsp -= 1;
}
rows++;
}
}
}