medon3

RepeatingNumbers

Oct 14th, 2022
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class RepeatingNumbers {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. Scanner sc = new Scanner(System.in);
  8.  
  9. int n = Integer.parseInt(sc.nextLine());
  10.  
  11. int arr [] = new int[n];
  12. int count [] = new int[10];
  13.  
  14. for (int i = 0; i < n; i++) {
  15. arr [i] = Integer.parseInt(sc.nextLine());
  16. }
  17.  
  18.  
  19. for (int i = 1; i <= 10; i++) {
  20. int counter = 0;
  21. for (int j = 0; j < arr.length; j++) {
  22. if(i == arr [j]){
  23. counter++;
  24. count [i-1] = counter;
  25. }
  26.  
  27. }
  28. }
  29. int maxCount = 0;
  30. int maxRepNumber = 0;
  31. for (int i = 0; i < count.length; i++) {
  32.  
  33. if(maxCount<count[i]){
  34. maxCount = count[i];
  35. maxRepNumber = i + 1;
  36. }
  37.  
  38. }
  39.  
  40. System.out.println(maxRepNumber);
  41.  
  42. }
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment