Patterns

class Pattern{
 public static void main(String ar[]){
  int n=5;
  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.print(i+1);
    }
    else{
     System.out.print(" ");
    }
   }
   System.out.println("");
  }
 }
}

No comments:

Popular Posts