Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner; public class T_1_Repeating_Numbers {
- public static void main(String[] args) { Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- int[] numbers = new int[n];
- int[] counter = new int[n];
- int theMostAppearsNumber = 0, numberForCompare = 0;
- if (n == 1) { theMostAppearsNumber = Integer.parseInt(scanner.nextLine());
- System.out.println(theMostAppearsNumber);return; }
- for (int i = 0; i < n; i++) {
- numbers[i] = Integer.parseInt(scanner.nextLine());
- }
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- if (numbers[i] == numbers[j]) {
- counter[i] ++;
- }
- }
- }
- for (int i = 0; i < n - 1 ; i++) {
- if (counter[i] > counter[i+1] && counter[i] > numberForCompare) theMostAppearsNumber = numbers[i];
- else if (counter[i] < counter[i+1] && counter[i+1] > numberForCompare) theMostAppearsNumber = numbers[i+1];
- else if (numbers[i] < numbers[i+1]) theMostAppearsNumber = numbers [i];
- else theMostAppearsNumber = numbers[i+1];
- }
- System.out.println(theMostAppearsNumber);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement