please check my code and tell if my approach is correct and not too much complicated.
my code:
Scanner s = new Scanner(System.in);
int n = s.nextInt();
// row
int row = 1;
// Ques 33:
// n = 10
// - - - - - - - - - 0
// - - - - - - - - 9 0 9
// - - - - - - - 8 9 0 9 8
// - - - - - - 7 8 9 0 9 8 7
// - - - - - 6 7 8 9 0 9 8 7 6
// - - - - 5 6 7 8 9 0 9 8 7 6 5
// - - - 4 5 6 7 8 9 0 9 8 7 6 5 4
// - - 3 4 5 6 7 8 9 0 9 8 7 6 5 4 3
// - 2 3 4 5 6 7 8 9 0 9 8 7 6 5 4 3 2
// 1 2 3 4 5 6 7 8 9 0 9 8 7 6 5 4 3 2 1
// work
int nsp = n - 1;
int nst = 1;
int zero = 0;
int val;
while (row <= n) {
val = n + 1 - row;
int csp = 1;
while (csp <= nsp) {
System.out.print("- ");
csp++;
}
int cst = 1;
while (cst <= nst) {
if (nsp + nst == n || csp + cst - 1 == n) // PROBLEM why i have
// to do
// csp+cst-1 and not
// csp+cst+1
{
System.out.print(zero + " ");
} else {
System.out.print(val + " ");
if (cst <= nst / 2) {
val++;
}
if (cst >= nst / 2) {
val--;
}
}
cst++;
}
// preparation
nst += 2;
nsp--;
System.out.println();
row++;
}