Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public int findMostFrequent() {
- ArrayList<Integer> array = new ArrayList<>();
- for (int[] line : matrix) {
- for (int el : line){
- array.add(el);
- }
- }
- Collections.sort(array);
- int maxCount = 0;
- int num = 0;
- for (int j : array) {
- int kol = 0;
- for (int value : array) {
- if (j == value) {
- kol++;
- }
- if (kol > maxCount) {
- maxCount = kol;
- num = j;
- }
- }
- }
- return num;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement