Advertisement
_Maximilian_

Задача 1

Mar 29th, 2021 (edited)
643
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1.  public static void main(String[] args) {
  2.  
  3.         int[] arr = {4, 5, 3, 2, 5, 5, 6};
  4.  
  5.         int max = Integer.MIN_VALUE;
  6.  
  7.         for (int i = 0; i < arr.length; i++) {
  8.             if (arr[i] > max) {
  9.                 max = arr[i];
  10.             }
  11.         }
  12.  
  13.         int[] B = new int[max + 1];
  14.  
  15.         for (int i = 0; i < arr.length; i++) {
  16.             B[arr[i]]++;
  17.         }
  18.         for (int i = 0; i <= max; i++) {
  19.             if (B[i] > 1) {
  20.  
  21.               System.out.println("The most common element in array is: " + "(" + i + ")");
  22.               System.out.println("How many times the most common element is repeated: " + "(" + B[i] + ")");
  23.             }
  24.         }
  25.     }
  26. }
  27.  
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement