Patterns

class Pattern{
 public static void main(String ar[]){
  int n=20;
  for(int i=0;i<n;i++){
   for(int j=1;j<=(2*n);j++){
    int start=n-i;
    int end=n+i;
    if((j>=start)&&(j<=(end))){
     System.out.printf("%2d",i+1);
    }
    else{
     System.out.printf("%2s"," ");
    }
   }
   System.out.println("");
  }
 }
}

No comments:

Popular Posts