/* package kitchen.task33; */ /** * [Одномерные массивы] * В массиве целых чисел с количеством элементов n найти наиболее * часто встречающееся число. Если таких чисел несколько, то * определить наименьшее из них. */ import java.util.Arrays; public class Main { public static final int ARRAY_MIN_LENGTH = 5; public static final int ARRAY_MAX_LENGTH = 9; public static final int ARRAY_ELEMENT_MIN_VALUE = 0; public static final int ARRAY_ELEMENT_MAX_VALUE = 9; public static final int TEST_COUNT = 5; test(TEST_COUNT); } public static int solve(int[] arr) { int result = OVER_9000; int count = 0; for (int i = 0; i < arr.length; i++) { int curCount = 1; for (int j = i + 1; j < arr.length; j++) { if (arr[i] == arr[j]) { curCount++; } } if (curCount > count) { count = curCount; result = arr[i]; } else if (curCount == count) { } } return result; } public static int[] generateInputData(int n) { int[] res = new int[n]; int diff = ARRAY_ELEMENT_MAX_VALUE - ARRAY_ELEMENT_MIN_VALUE + 1; for (int i = 0; i < n; i++) { } return res; } public static void test(int testCount) { for (int i = 1; i <= testCount; i++) { int diff = ARRAY_MAX_LENGTH - ARRAY_MIN_LENGTH + 1; int[] arr = generateInputData(n); int res = solve(arr); } } }
Standard input is empty
Test #001 [1, 1, 8, 7, 3, 9, 6, 6, 6] 6 Test #002 [2, 2, 6, 1, 2, 8] 2 Test #003 [2, 9, 6, 4, 2, 5, 6, 1, 2] 2 Test #004 [2, 8, 5, 3, 1, 8, 0] 8 Test #005 [3, 7, 1, 0, 7] 7