Below is the code that i have written for pattern 33, and i got output for it, can u guide me whether it is ok or can i still optimize it?
import java.util.Scanner;
public class Pattern33 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int rows = n;
int nst = 1;
int nsp= n - 1;
int val;
while (rows >= 1) {
val=rows;
for(int csp=1;csp<=nsp;csp++)
System.out.print(" "+" ");
for(int cst=1;cst<=nst;cst++) {
if(cst==n)
System.out.print("0"+" ");
else {
if(cst<=nst/2) {
System.out.print(val+" ");
val++;
}
else if(cst==nst/2+1)
System.out.print("0"+" ");
else {
val--;
System.out.print(val+" ");
}
}
}
System.out.println();
nst+=2;
nsp--;
rows--;
}
}
}