Page 421 - Cs_withBlue_J_C11_Flipbook
P. 421

22                  return max;
                   23              else

                   24              {
                   25                  max=Math.max(max,arr[i]); // finding maximum

                   26                  return maximum(i+1); // recursive case
                   27              }

                   28          }
                   29          void print() // display

                   30          {
                   31              System.out.println("The array is");

                   32              for(int i=0;i<n;i++)
                   33              {

                   34                   System.out.println(arr[i]);
                   35              }

                   36              int m=maximum(0);
                   37              System.out.println("The largest number is: "+m);

                   38          }
                   39          public static void main(int s)

                   40          {
                   41              Maxnum obj = new Maxnum(s);
                   42              obj.fillarray();

                   43              obj.print();

                   44          }
                   45      }

                 The output of the preceding program is as follows:
















                 Enter 8 elements
                 7 28 35 81 44 67 92 17
                 The array is
                 7


                                                                                                                       419
                                                                                                           Recursion   419
   416   417   418   419   420   421   422   423   424   425   426