Page 316 - Computer science 868 Class 12
P. 316

36                   i=j-1;
                37                   if(freq > 1)

                38                   {
                39                        System.out.println("The element is " + ar[i] + " and its frequency
                                            is " + freq);
                40                   }

                41               }
                42           }

                43          public static void main()
                44          {

                45              count_frequency ob= new count_frequency();
                46              ob.input();

                47              ob.display();
                48          }

                49        }

              The output of the preceding program is as follows:
              Enter the size of the array
              5
              Enter array elements in sorted order
              1 1 2 3 3

              The element is 1 and its frequency is 2
              The element is 3 and its frequency is 2


                Program 4      Write a program to find two elements in an array such that the difference between them is
                               the largest.

                 1       import java.util.*;

                 2       class large_diff
                 3       {
                 4           public static void main()

                 5           {

                 6                int n, x, count = 0, i = 0, temp = 0, diff, greatest_diff=0, a1 = 0, a2
                                  = 0;
                 7               Scanner s = new Scanner(System.in);
                 8               System.out.print("Enter the size of the array ");

                 9               n = s.nextInt();







                314314  Touchpad Computer Science-XII
   311   312   313   314   315   316   317   318   319   320   321