when i assign value to VAL variable outside the while loop, it does not print the correct number pattern, why?
my code:
Scanner s = new Scanner(System.in);
int n = s.nextInt();
// row
int row = 1;
// Ques 26:
// n = 5
// - - - - 1
// - - - 1 2 3
// - - 1 2 3 4 5
// - 1 2 3 4 5 6 7
// 1 2 3 4 5 6 7 8 9
// work
int nsp = n-1;
int nst = 1;
int val;
while (row <= n) {
int csp = 1;
while (csp <= nsp) {
System.out.print("\t");
csp++;
}
val=1;
int cst = 1;
while (cst <= nst) {
System.out.print(val + "\t");
cst++;
val++;
}
// preparation
nsp--;
nst = nst + 2;
System.out.println();
row++;
}