Page 323 - Cs_withBlue_J_C11_Flipbook
P. 323
31 freq[j]= freq[j] + freq[j+1];
32 freq[j+1] = freq[j] - freq[j+1];
33 freq[j]= freq[j] - freq[j+1];
34 }
35 }
36 }
37 System.out.println("Number\tFrequency");
38 count = 0;
39 for (i = 0; i < n - 1; i++)
40 {
41 count++;
42 if (freq[i] != freq[i + 1])
43 {
44 System.out.println(freq[i] + "\t" + count);
45 count = 0;
46 }
47 }
48 //Print frequency of last element
49 count++;
50 System.out.println(freq[n - 1] + "\t" + count);
51 }
52 }
53 }
The output of the preceding program is as follows:
Enter the size of the array: 5
Enter elements in the array one by one:
11
33
11
11
33
Number Frequency
11 3
33 2
321
Arrays 321

