Question No:3i/p: 3
11
1221
123321
1221
11
public class Pattern1221 {
public static void main(String[] args) {
int n=3;
int p=0,sp=n;
for(int i=1;i<=2*n-1;i++){
if(i<=n){
sp=n-i;
p++;
}
else{
sp++;
p--;
}
for(int j=1;j<=sp;j++){
System.out.print(" ");
}
for(int k=1;k<=p;k++){
System.out.print(k);
}
for(int l=p;l>=1;l--){
System.out.print(l);
}
System.out.println();
}
}
}
No comments:
Post a Comment