please check my code is the logic i am using is correct.
the result is correct the number pattern is printing correctly.
my code:
Scanner s = new Scanner(System.in);
int n = s.nextInt();
// row
int row = 1;
// Ques 29:
// n = 5
// - - - - 1
// - - - 2 0 2
// - - 3 0 0 0 3
// - 4 0 0 0 0 0 4
// 5 0 0 0 0 0 0 0 5
// work
int nsp = n - 1;
int nst = 1;
int val;
int zero = 0;
while (row <= n) {
val = row;
for (int csp = 1; csp <= nsp; csp++) {
System.out.print("\t");
}
for (int cst = 1; cst <= nst; cst++) {
if (cst == 1 || cst == nst) {
System.out.print(val + "\t");
} else {
System.out.print(zero + "\t");
}
}
// preparation
nsp--;
nst = nst + 2;
System.out.println();
row++;
}