From b3beaaa0a1b69ccc50f2a311b566b6924b6d4bad Mon Sep 17 00:00:00 2001 From: Valeriy Date: Fri, 21 Feb 2025 18:22:29 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=94=D0=97=20Kotlin=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/ru/otus/homework/fizzbuzz.kt | 18 +++++++++++++++--- src/main/kotlin/ru/otus/homework/sumoftwo.kt | 14 +++++++++++++- .../kotlin/ru/otus/homework/SumoftwoTest.kt | 7 +++++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/ru/otus/homework/fizzbuzz.kt b/src/main/kotlin/ru/otus/homework/fizzbuzz.kt index 6e04be1..9a89a9f 100644 --- a/src/main/kotlin/ru/otus/homework/fizzbuzz.kt +++ b/src/main/kotlin/ru/otus/homework/fizzbuzz.kt @@ -1,6 +1,18 @@ package ru.otus.homework - -fun fizzbuzz(n: Int): Array { - TODO("Выполните задание") +fun fizzbuzz(n: Int): Array{ + val array = Array(n){it} + val expectedArray = Array(n){""} + for (i in array) { + if (i%3==0) { + expectedArray[i] += "Fizz" + } + if (i%5==0) { + expectedArray[i] += "Buzz" + } + if (expectedArray[i] == "") { + expectedArray[i] = i.toString() + } + } + return expectedArray } \ No newline at end of file diff --git a/src/main/kotlin/ru/otus/homework/sumoftwo.kt b/src/main/kotlin/ru/otus/homework/sumoftwo.kt index 70d72e5..b69c5a0 100644 --- a/src/main/kotlin/ru/otus/homework/sumoftwo.kt +++ b/src/main/kotlin/ru/otus/homework/sumoftwo.kt @@ -1,6 +1,18 @@ package ru.otus.homework +fun main(){ + sumOfTwo(intArrayOf(3, 2, 4), 6) +} fun sumOfTwo(numbers: IntArray, target: Int): IntArray { - TODO("Выполните задание") + + if (numbers.size<2) throw IllegalArgumentException() + + for (i in numbers.indices){ + for (j in i+1.. { + sumOfTwo(intArrayOf(2), 6) + } + } } \ No newline at end of file From 98b48aeab5adb087cdd280df7e39649fff99db63 Mon Sep 17 00:00:00 2001 From: Valeriy Date: Fri, 21 Feb 2025 18:24:01 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BB=20main=20fun?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/ru/otus/homework/sumoftwo.kt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/kotlin/ru/otus/homework/sumoftwo.kt b/src/main/kotlin/ru/otus/homework/sumoftwo.kt index b69c5a0..28f3644 100644 --- a/src/main/kotlin/ru/otus/homework/sumoftwo.kt +++ b/src/main/kotlin/ru/otus/homework/sumoftwo.kt @@ -1,9 +1,5 @@ package ru.otus.homework -fun main(){ - sumOfTwo(intArrayOf(3, 2, 4), 6) -} - fun sumOfTwo(numbers: IntArray, target: Int): IntArray { if (numbers.size<2) throw IllegalArgumentException()