Section 1 basics number pattern 26, problem with the VAL variable

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++;
	}

Hii Nipun,
If you assign value to variable val where you declared the variable val i.e. outside the while loop then after 1st iteration of while loop value of val variable will become 2 and that’s why it does not print the correct output.