Pascal triangle pattern3

i am not getting the logic how to print the middle value

my code:

Scanner s = new Scanner(System.in);
int n = s.nextInt();

	// row
	int row = 1;

	// work
	int nst = 1;
	int val;
	while (row <= n) {
		int cst = 1;

		val = 1;
		while (cst <= nst) {
			int one = 1;

			if (row == 1 || row == 2) {
				System.out.print(one);
			} else {
				System.out.print(val);
				if (cst <= nst / 2) {
					val++;
				} else {
					val--;
				}
			}
			cst++;
		}
		// preparation
		nst++;
		System.out.println();
		row++;
	}

Hi Nipun,
See Pascal triangle is a triangle of binomial coefficients. Every element in line L and at ith column is C(L, i), where we start counting line and column from 0.