Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import kotlin.random.Random
- fun main() {
- val numbers = Array(10) { Random.nextInt(1, 11) }
- println("Исходные числа: ${numbers.contentToString()}")
- val (hasDuplicates, average) = findAverageWithoutDuplicates(numbers)
- if (hasDuplicates) {
- println("Среди чисел есть повторяющиеся.")
- } else {
- println("Среди чисел нет повторяющихся.")
- }
- println("Среднее арифметическое без учета повторов: $average")
- }
- fun findAverageWithoutDuplicates(numbers: Array<Int>): Pair<Boolean, Double> {
- val distinctNumbers = numbers.distinct()
- val hasDuplicates = numbers.size != distinctNumbers.size
- val sum = distinctNumbers.sum()
- val count = distinctNumbers.size.toDouble()
- val average = sum / count
- return Pair(hasDuplicates, average)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement