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=2n-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
Getting wrong output in the question pattern mountain
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.