Page 314 - Computer science 868 Class 12
P. 314

23              }
                24              for (i = 2; i < arr.length; i++)

                25              {
                26                    if (arr[i] > large1)
                27                    {

                28                          large2 = large1;

                29                          large1 = arr[i];
                30                    }
                31                    else if (arr[i] > large2 && arr[i] != large1)

                32                    {
                33                          large2 = arr[i];

                34                    }
                35              }

                36              System.out.println ("The First largest is " + large1);
                37              System.out.println ("The Second largest is " + large2);

                38          }
                39       }


              The output of the preceding program is as follows:
              Enter no. of elements you want in array:5
              Enter all the elements:
              2 3 5 1 23
              The First largest is 23

              The Second largest is 5



                Program 3      Given an array of integers, find and print the repeated elements and their frequency of
                               repetition.
                               Example:
                               Array: [1,2,3,4,5,5,3]

                               Output:
                               Element—–>Frequency
                               The element is 3 and its frequency is 2
                               The element is 5 and its frequency is 2


                 1       import java.util.*;
                 2       class count_frequency







                312312  Touchpad Computer Science-XII
   309   310   311   312   313   314   315   316   317   318   319