From b35235d28c673e49719889aef0399bba17d7af11 Mon Sep 17 00:00:00 2001 From: "Mikhail.Makhonin" Date: Wed, 20 Aug 2025 23:07:06 +0300 Subject: [PATCH 1/3] =?UTF-8?q?-=20=D0=9F=D0=BE=D0=B4=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=B8=D0=BB=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D1=83?= =?UTF-8?q?=D1=80=D0=B0=D1=86=D0=B8=D1=8E=20=D1=81=D0=B1=D0=BE=D1=80=D1=89?= =?UTF-8?q?=D0=B8=D0=BA=D0=B0=20=D0=BF=D0=BE=D0=B4=20=D1=81=D0=B5=D0=B1?= =?UTF-8?q?=D1=8F:=20=D1=83=20=D0=BC=D0=B5=D0=BD=D1=8F=20AndroidStudio=20-?= =?UTF-8?q?=202022.3.1=20=D0=B8=20jdk=20-=2021=20-=20=D0=A0=D0=B5=D0=B0?= =?UTF-8?q?=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D1=84=D1=83=D0=BD?= =?UTF-8?q?=D0=BA=D1=86=D0=B8=D0=B9=20fizzbuzz=20=D0=B8=20sumOfTwo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 16 +++++++------ gradle/wrapper/gradle-wrapper.properties | 4 ++-- src/main/kotlin/ru/otus/homework/Main.kt | 17 ++++++++++++++ src/main/kotlin/ru/otus/homework/fizzbuzz.kt | 24 +++++++++++++++++++- src/main/kotlin/ru/otus/homework/sumoftwo.kt | 21 ++++++++++++++++- 5 files changed, 71 insertions(+), 11 deletions(-) create mode 100644 src/main/kotlin/ru/otus/homework/Main.kt diff --git a/build.gradle b/build.gradle index f4ad580..4db23c8 100644 --- a/build.gradle +++ b/build.gradle @@ -1,16 +1,18 @@ + plugins { - id 'org.jetbrains.kotlin.jvm' version '2.0.21' + id 'org.jetbrains.kotlin.jvm' version '2.1.0' } java { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 + toolchain { + languageVersion = JavaLanguageVersion.of(21) + } } kotlin { - jvmToolchain { - languageVersion = JavaLanguageVersion.of(17) - } + jvmToolchain(21) } test { @@ -25,6 +27,6 @@ repositories { } dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib" + implementation("org.jetbrains.kotlin:kotlin-stdlib:1.9.0") implementation 'org.junit.jupiter:junit-jupiter:5.8.1' } \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index c0bd7c9..df26d26 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Oct 09 12:41:49 CEST 2023 +#Wed Aug 20 20:57:55 MSK 2025 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/kotlin/ru/otus/homework/Main.kt b/src/main/kotlin/ru/otus/homework/Main.kt new file mode 100644 index 0000000..7c3ea17 --- /dev/null +++ b/src/main/kotlin/ru/otus/homework/Main.kt @@ -0,0 +1,17 @@ +package ru.otus.homework + +fun main() { + val strings: Array = fizzbuzz(16) + + for(string in strings){ + print("$string , ") + } + + + println("") + val intArray: IntArray = sumOfTwo(intArrayOf(2, 7, 11, 15), 9) + for(int in intArray){ + print("$int , ") + } + +} \ No newline at end of file diff --git a/src/main/kotlin/ru/otus/homework/fizzbuzz.kt b/src/main/kotlin/ru/otus/homework/fizzbuzz.kt index 6e04be1..43d0371 100644 --- a/src/main/kotlin/ru/otus/homework/fizzbuzz.kt +++ b/src/main/kotlin/ru/otus/homework/fizzbuzz.kt @@ -2,5 +2,27 @@ package ru.otus.homework fun fizzbuzz(n: Int): Array { - TODO("Выполните задание") + var strings: Array = emptyArray() + var isDivisionBy3 = false + var isDivisionBy5 = false + + for(currentValue in 0.rangeUntil(n)) { + if(currentValue != 0) { + isDivisionBy3 = currentValue % 3 == 0 + isDivisionBy5 = currentValue % 5 == 0 + } + + strings += if(isDivisionBy3 && isDivisionBy5 || currentValue == 0){ + "FizzBuzz" + } else if(isDivisionBy3){ + "Fizz" + } else if(isDivisionBy5){ + "Buzz" + } else { + currentValue.toString() + } + + } + + return strings } \ 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..ccc7aba 100644 --- a/src/main/kotlin/ru/otus/homework/sumoftwo.kt +++ b/src/main/kotlin/ru/otus/homework/sumoftwo.kt @@ -1,6 +1,25 @@ package ru.otus.homework +import java.lang.IllegalArgumentException + fun sumOfTwo(numbers: IntArray, target: Int): IntArray { - TODO("Выполните задание") + //var intArray: IntArray = emptyArray().toIntArray() + val indexes = ArrayList() + + for((index, currentValue) in numbers.withIndex()) { + var i = 1 + + while (i < numbers.size) { + if(currentValue + numbers[i] == target){ + indexes.add(index) + indexes.add(i) + return indexes.toIntArray() + } + ++i; + } + } + + throw IllegalArgumentException("Сумма не найдена!") + } \ No newline at end of file From 9529efac61bef9ae86515116343cad76413445e5 Mon Sep 17 00:00:00 2001 From: "Mikhail.Makhonin" Date: Fri, 22 Aug 2025 12:32:28 +0300 Subject: [PATCH 2/3] =?UTF-8?q?-=20=D0=9F=D0=BE=D0=B4=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=B8=D0=BB=20fizzbuzz=20=D0=B8=20sumOfTwo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/ru/otus/homework/fizzbuzz.kt | 6 ++---- src/main/kotlin/ru/otus/homework/sumoftwo.kt | 16 ++++++---------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/ru/otus/homework/fizzbuzz.kt b/src/main/kotlin/ru/otus/homework/fizzbuzz.kt index 43d0371..75f12b6 100644 --- a/src/main/kotlin/ru/otus/homework/fizzbuzz.kt +++ b/src/main/kotlin/ru/otus/homework/fizzbuzz.kt @@ -7,10 +7,8 @@ fun fizzbuzz(n: Int): Array { var isDivisionBy5 = false for(currentValue in 0.rangeUntil(n)) { - if(currentValue != 0) { - isDivisionBy3 = currentValue % 3 == 0 - isDivisionBy5 = currentValue % 5 == 0 - } + isDivisionBy3 = currentValue % 3 == 0 + isDivisionBy5 = currentValue % 5 == 0 strings += if(isDivisionBy3 && isDivisionBy5 || currentValue == 0){ "FizzBuzz" diff --git a/src/main/kotlin/ru/otus/homework/sumoftwo.kt b/src/main/kotlin/ru/otus/homework/sumoftwo.kt index ccc7aba..bf9ca5d 100644 --- a/src/main/kotlin/ru/otus/homework/sumoftwo.kt +++ b/src/main/kotlin/ru/otus/homework/sumoftwo.kt @@ -4,19 +4,15 @@ import java.lang.IllegalArgumentException fun sumOfTwo(numbers: IntArray, target: Int): IntArray { - //var intArray: IntArray = emptyArray().toIntArray() val indexes = ArrayList() for((index, currentValue) in numbers.withIndex()) { - var i = 1 - - while (i < numbers.size) { - if(currentValue + numbers[i] == target){ - indexes.add(index) - indexes.add(i) - return indexes.toIntArray() - } - ++i; + for (i in 1 until numbers.size) { + if (currentValue + numbers[i] == target) { + indexes.add(index) + indexes.add(i) + return indexes.toIntArray() + } } } From 44c754d767aef149dfc8cbfa5421cf7301a177da Mon Sep 17 00:00:00 2001 From: "Mikhail.Makhonin" Date: Mon, 25 Aug 2025 09:37:30 +0300 Subject: [PATCH 3/3] =?UTF-8?q?-=20=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F=20fizzbuzz=20=D1=81=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=BC=D0=BE=D1=89=D1=8C=D1=8E=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82?= =?UTF-8?q?=D1=80=D1=83=D0=BA=D1=82=D0=BE=D1=80=D0=B0=20Array?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/ru/otus/homework/fizzbuzz.kt | 27 +++++--------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/src/main/kotlin/ru/otus/homework/fizzbuzz.kt b/src/main/kotlin/ru/otus/homework/fizzbuzz.kt index 75f12b6..99479e8 100644 --- a/src/main/kotlin/ru/otus/homework/fizzbuzz.kt +++ b/src/main/kotlin/ru/otus/homework/fizzbuzz.kt @@ -1,26 +1,11 @@ package ru.otus.homework -fun fizzbuzz(n: Int): Array { - var strings: Array = emptyArray() - var isDivisionBy3 = false - var isDivisionBy5 = false - - for(currentValue in 0.rangeUntil(n)) { - isDivisionBy3 = currentValue % 3 == 0 - isDivisionBy5 = currentValue % 5 == 0 - - strings += if(isDivisionBy3 && isDivisionBy5 || currentValue == 0){ - "FizzBuzz" - } else if(isDivisionBy3){ - "Fizz" - } else if(isDivisionBy5){ - "Buzz" - } else { - currentValue.toString() +fun fizzbuzz(n: Int): Array = Array(n){ i -> + when { + i == 0 || (i % 3 == 0 && i % 5 == 0) -> "FizzBuzz" + i % 3 == 0 -> "Fizz" + i % 5 == 0 -> "Buzz" + else -> i.toString() } - - } - - return strings } \ No newline at end of file