public class MountainPattern {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int nst = 1;
int nsp = 2 * n - 3;
int val;
int row = 1;
while (row <= n) {
val = row;
for (int cst = 1; cst <= nst; cst++) {
System.out.print(val + "\t");
val++;
}
for (int csp = 1; csp <= nsp; csp++) {
System.out.print("\t");
}
int cst = 1;
if (row == n) {
cst = 2;
}
for (; cst <= nst; cst++) {
System.out.print(val + "\t");
val--;
}
System.out.println();
if (cst <= nst / 2) {
val++;
} else {
val--;
}
nst = nst + 1;
nsp = nsp - 2;
row = row + 1;
}
}
}
this is my code for mountain pattern. I am able to print the same pattern but the values are not same i mean i dont know how intialize val variable for this question.