for n=5 i got the answer but for random valuess of n the lower part of pattern is not matching
package basics;
import java.util.*;
public class check {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n=0;
if(scn.hasNext()) {
n=scn.nextInt();
}
int i,j,space,value;
value=n;
//upper part
for(i=0;i<=n;i++) {
value=n-i;
for(space=0;space<=i;space++) {
System.out.print(" ");
}
for(j=i;j<=2*n-i;j++) {
System.out.print(value+" ");
if(j<=n && value>0) {
value--;
}
else {
value++;
}
}
System.out.println();
}
//lower part
for(i=0;i<n;i++) {
value=i+1;
int count=0;
for(space=0;space<n-i;space++) {
System.out.print(" ");
count++;
}
for(j=0;j<(n/2)+2*i+1;j++) {
System.out.print(value+" ");
if(j<=n-space+1 && value>0) {
value--;
}
else {
value++;
}
}
System.out.println();
}
}
}
this is my code