Задачи на типы в Java. Часть 8
Дан следующий код:
static ??? test(??? aaa) { int sum = 0; for (num in aaa) { sum += num; } return sum; } list = List.of(1, 2, 3, 4, 5);
total = test(list);
Явно укажите тип переменных, параметров и возвращаемого значения.
Дан следующий код:
static ??? test(??? aaa, ??? bbb) { List<Integer> result = mutableListOf<Int>(); for (item in aaa) { if (item in bbb) { result.add(item) } } return result; } list1 = List.of(1, 2, 3, 4, 5);
list2 = List.of(3, 4, 5, 6, 7);
intersection = test(list1, list2);
Явно укажите тип переменных, параметров и возвращаемого значения.
Дан следующий код:
static ??? test(??? aaa) { int sum = 0; var num = aaa; while (num > 0) { sum += num % 10; num /= 10 } return sum; } number = 12345;
digitSum = test(number);
Явно укажите тип переменных, параметров и возвращаемого значения.
Дан следующий код:
static ??? test(??? aaa) { List<Integer> result = mutableListOf<String>(); for (str in aaa) { if (str.length() > 3) { result.add(str) } } return result; } words = List.of("cat", "dog", "elephant", "fox");
longWords = test(words);
Явно укажите тип переменных, параметров и возвращаемого значения.
Дан следующий код:
static ??? test(??? aaa) { var max = aaa[0]; for (num in aaa) { if (num > max) { max = num; } } return max; } numbers = List.of(10, 5, 8, 15, 3);
maximum = test(numbers);
Явно укажите тип переменных, параметров и возвращаемого значения.
Дан следующий код:
static ??? test(??? aaa) { Map<String, String> result = mutableMapOf<Char, Int>(); for (char in aaa) { result[char] = result.getOrDefault(char, 0) + 1 } return result; } text = "hello world";
charCount = test(text);
Явно укажите тип переменных, параметров и возвращаемого значения.
Дан следующий код:
static ??? test(??? aaa, ??? bbb) { List<Integer> result = mutableListOf<Int>(); for (i in aaa.indices) { result.add(aaa[i] + bbb[i]) } return result; } array1 = new int[] {1, 2, 3, 4, 5} array2 = new int[] {5, 4, 3, 2, 1} sumArray = test(array1, array2);
Явно укажите тип переменных, параметров и возвращаемого значения.
Дан следующий код:
static ??? test(??? aaa) { Set<Integer> result = mutableSetOf<Int>(); for (num in aaa) { if (num % 2 == 0) { result.add(num) } } return result; } numbers = Set.of(1, 2, 3, 4, 5, 6, 7, 8);
evenNumbers = test(numbers);
Явно укажите тип переменных, параметров и возвращаемого значения.