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..99479e8 100644 --- a/src/main/kotlin/ru/otus/homework/fizzbuzz.kt +++ b/src/main/kotlin/ru/otus/homework/fizzbuzz.kt @@ -1,6 +1,11 @@ package ru.otus.homework -fun fizzbuzz(n: Int): Array { - TODO("Выполните задание") +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() + } } \ 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..bf9ca5d 100644 --- a/src/main/kotlin/ru/otus/homework/sumoftwo.kt +++ b/src/main/kotlin/ru/otus/homework/sumoftwo.kt @@ -1,6 +1,21 @@ package ru.otus.homework +import java.lang.IllegalArgumentException + fun sumOfTwo(numbers: IntArray, target: Int): IntArray { - TODO("Выполните задание") + val indexes = ArrayList() + + for((index, currentValue) in numbers.withIndex()) { + for (i in 1 until numbers.size) { + if (currentValue + numbers[i] == target) { + indexes.add(index) + indexes.add(i) + return indexes.toIntArray() + } + } + } + + throw IllegalArgumentException("Сумма не найдена!") + } \ No newline at end of file