Page 375 - ComputerScience_Class_11
P. 375

5          {
                   6              Scanner sc = new Scanner(System.in);

                   7              int[][] array = new int[3][3];
                   8              int flatArray[] = new int[9];

                   9              int index = 0;
                  10              System.out.println("Enter 9 elements for the 3x3 array:");

                  11              for (int i = 0; i < 3; i++)
                  12              {

                  13                  for (int j = 0; j < 3; j++)

                  14                  {
                  15                      array[i][j] = sc.nextInt();

                  16                  }
                  17              }

                  18              for (int i = 0; i < 3; i++)
                  19              {

                  20                  for (int j = 0; j < 3; j++)

                  21                  {
                  22                      flatArray[index++] = array[i][j];

                  23                  }
                  24              }

                  25              for (int i = 0; i < flatArray.length - 1; i++)
                  26              {

                  27                  for (int j = 0; j < flatArray.length - i - 1; j++)

                  28                  {
                  29                      if (flatArray[j] > flatArray[j + 1])

                  30                      {
                  31                          int temp = flatArray[j];

                  32                          flatArray[j] = flatArray[j + 1];
                  33                          flatArray[j + 1] = temp;

                  34                      }

                  35                  }
                  36              }

                  37              System.out.println("Array arranged in ascending order:");





                                                                                                           Arrays  373
   370   371   372   373   374   375   376   377   378   379   380