Рет қаралды 14,828
We have to write a program in Java to find the frequency of all the elements of the given array.
Frequency means the number of times an element occurs in an array.
For eg, consider the array 20,20,30,30,30,40 the output will be:-
20 2
30 3
40 1
What's the logic for the program question.
You can simply find the solution by taking the frequency of element 1 as 1 by default and checking for further elements if they are equal to the previous element.
If yes increase the frequency variable by 1.
If the condition breaks, set the frequency variable to 1 again and do the same process.
In this way, you will be able to find the frequency of the elements.
There's one condition that we have missed in this logic.
Check out the complete program to know it and the code to write the program.
For more information, fill out this form: forms.gle/8eiUmM92Fx563Aen9
or call us at 8884881203
Facebook: / thetapacademy
Instagram: / tapacademy_online
Linkedin: / 73820805
Website: www.thetapacademy.com
#java #array #arrayjava #dsa #dsacourse #courseofdsa #datastructure #coding #programming