Scanner scn=new Scanner(System.in);
int n=scn.nextInt();
int nst=1;
int nsp=n-1;
int val;
int row=1;
while(row<=n) {
val=row;
for(int csp=1;csp<=nsp;csp++) {
System.out.print("\t");
}
int cst=1;
for( ;cst<=nst;cst++) {
System.out.print(val+"\t");
}
if(cst<=nst/2) {
val++;
}
else {
val–;
}
System.out.println();
nsp–;
nst+=2;
row++;
}
Doubt about pattern triangle
https://ide.codingblocks.com/s/265795 corrected code.
The numbers are first in increasing order then in decreasing order. So instead of printing the same number you need to put the if condition inside the for loop.