Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- int[] arr = {4, 5, 3, 2, 5, 5, 6};
- int max = Integer.MIN_VALUE;
- for (int i = 0; i < arr.length; i++) {
- if (arr[i] > max) {
- max = arr[i];
- }
- }
- int[] B = new int[max + 1];
- for (int i = 0; i < arr.length; i++) {
- B[arr[i]]++;
- }
- for (int i = 0; i <= max; i++) {
- if (B[i] > 1) {
- System.out.println("The most common element in array is: " + "(" + i + ")");
- System.out.println("How many times the most common element is repeated: " + "(" + B[i] + ")");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement