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