fork download
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5. public static void main(String[] args) {
  6. Scanner scan = new Scanner(System.in);
  7. String input = scan.nextLine();
  8. scan.close();
  9. String[] splitted = input.split(" ");
  10. int[] arr = new int[splitted.length];
  11. for (int i = 0; i < splitted.length; i++) {
  12. arr[i] = Integer.parseInt(splitted[i]);
  13. }
  14. checkRep(arr);
  15. }
  16. public static void checkRep(int[] arr) {
  17. boolean[] checked = new boolean[arr.length];
  18. Arrays.fill(checked, false);
  19. for (int i = 0; i < arr.length; i++) {
  20. if (checked[i] == true) {
  21. continue;
  22. }
  23. int count = 1;
  24. for (int j = i + 1; j < arr.length; j++) {
  25. if (arr[i] == arr[j]) {
  26. count++;
  27. checked[j] = true;
  28. }
  29. }
  30. System.out.println(arr[i] + " " + count);
  31. }
  32. }
  33. }
Success #stdin #stdout 0.16s 41796KB
stdin
3 1 2 2 1 3 5 3 3 2
stdout
3 4
1 2
2 3
5 1