Getting wrong output in the question pattern mountain

import java.util.;
public class Mountain {
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 row=1;
while(row<=n) {
for(int cst=1;cst<=nst;cst++) {
System.out.print(cst+" β€œ);
}
for(int csp=1;csp<=nsp;csp++) {
System.out.print(” β€œ);
}
int cst=1;
if(row==n) {
cst=2;
}
for(;cst<=nst;cst++) {
System.out.print(cst+” ");
}
System.out.println();
nst++;
nsp=nsp-2;
row++;
sc.close();
}
}
}
in this problem i am getting output as
1 1
1 2 1 2
1 2 3 1 2 3
1 2 3 4 1 2 3 4
1 2 3 4 5 2 3 4 5

Please save your code on the online IDE (ide.codingblocks.com) and share the corresponding link with me here.

already shared code you just have to copy and paste

Submit your code like this from the next time. https://ide.codingblocks.com/s/580785
First of all the elements should be separated with a tab rather than space (use β€œ\t” instead of " ").
Secondly, you need to print the elements in reverse order while printing the 2nd peak ie.the right sided pattern must be like
1
2 1
3 2 1
4 3 2 1

So, try changing the last loop accordingly.

the code which you have sent is giving correct pattern but numbers are not positioned in correct way

As I mentioned earlier, you need to correct the last loop for every row. Try correcting the last loop once again if you’re still facing any error i’ll resolve it.
Secondly, you need to print the elements in reverse order while printing the 2nd peak ie.the right sided pattern must be like
1
2 1
3 2 1
4 3 2 1

So, try changing the last loop accordingly.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.