Page 387 - ComputerScience_Class_11
P. 387

19                  {

                  20                      sparr[i][right] = num++;
                  21                  }

                  22                  right--;
                  23                  for (int i = right; i >= left; i--)

                  24                  {

                  25                      sparr[bottom][i] = num++;
                  26
                                      }
                  27                  bottom--;
                  28                  for (int i = bottom; i >= top; i--)

                  29                  {
                  30                      sparr[i][left] = num++;

                  31                  }

                  32                  left++;
                  33              }

                  34          }
                  35          void display()

                  36          {
                  37              for (int i = 0; i < s; i++)

                  38              {

                  39                  for (int j = 0; j < s; j++)
                  40                  {

                  41                      System.out.print(sparr[i][j] + " ");
                  42                  }

                  43                  System.out.println();
                  44              }

                  45          }

                  46          public static void main(String args[])
                  47          {

                  48              Spiral spiralMatrix = new Spiral(5);
                  49              spiralMatrix.display();

                  50          }
                  51      }






                                                                                                           Arrays  385
   382   383   384   385   386   387   388   389   390   391   392