menu

Kotlin Basic Programs for Beginners


1.

What is the output of the following Kotlin code?

fun main() {
val nums = arrayOf(1, 2, 3, 4, 5)
val result = nums.all { it % 2 == 0 }
println(result)
}

1

0

2

Compilation error


2.

What is the output of the following Kotlin code?

fun main() {
val nums = arrayOf(1, 2, 3, 4, 5)
val result = nums.any { it % 2 == 0 }
println(result)
}

1

0

2

Compilation error


3.

What is the output of the following Kotlin code?

fun main() {
val nums = arrayOf(1, 2, 3, 4, 5)
val result = nums.min()
println(result)
}

1

5

null

Compilation error


4.

What is the output of the following Kotlin code?

fun main() {
val str = "hello, world"
val result = str.filter { it.isLetter() }
println(result)
}

helloworld

hello,world

hello world

Compilation error


5.

What is the output of the following Kotlin code?

fun main() {
var i = 0
while (i < 5) {
println("Hello, world!")
i++
}
}

Compilation error

Runtime error

Hello, world!

Hello, world! (printed 5 times)


6.

What is the output of the following Kotlin code?

fun main() {
val nums = arrayOf(1, 2, 3, 4, 5)
val result = nums.last { it % 2 == 0 }
println(result)
}

2

4

null

Compilation error


7.

What is the output of the following Kotlin code?

fun main() {
val nums = arrayOf(1, 2, 3, 4, 5)
val result = nums.filter { it % 2 == 0 }
println(result)
}

[1, 3, 5]

[2, 4]

[1, 2, 3, 4, 5]

Compilation error


8.

What is the output of the following Kotlin code?

fun main() {
val nums = arrayOf(1, 2, 3, 4, 5)
val result = nums.max()
println(result)
}

1

5

null

Compilation error


9.

What is the output of the following Kotlin code?

fun main() {
val arr = arrayOf(1, 2, 3, 4, 5)
for (i in arr.indices step 2) {
println(arr[i])
}
}

1 2 3 4 5

1 3 5

2 4

Compilation error


10.

What is the output of the following Kotlin code?

fun main() {
val nums = arrayOf(1, 2, 3, 4, 5)
val result = nums.first { it % 2 == 0 }
println(result)
}

2

4

null

Compilation error