Join Now
Home Aptitude Reasoning DI VA GK CA CA Hindi Quiz Placements
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
fun main() { val nums = arrayOf(1, 2, 3, 4, 5) val result = nums.all { it % 2 == 0 } println(result)}
1
0
2
fun main() { val name: String? = null println(name?.length ?: -1)}
null
-1
Runtime error
fun main() { val nums = arrayOf(1, 2, 3, 4, 5) val result = nums.last { it % 2 == 0 } println(result)}
4
fun main() { val nums = arrayOf(1, 2, 3, 4, 5) val result = nums.sum() println(result)}
10
15
20
fun main() { val num1 = 10 val num2 = 20 val result = if (num1 > num2) "num1 is greater than num2" else "num2 is greater than num1" println(result)}
num1 is greater than num2
num2 is greater than num1
Both num1 and num2 are equal
fun main() { val str = "hello, world" val result = str.split(" ") println(result)}
["hello,", "world"]
[hello,, world]
[hello, world]
fun main() { val nums = arrayOf(1, 2, 3, 4, 5) val sum = nums.fold(0) { acc, num -> acc + num } println(sum)}
30
fun main() { val nums = arrayOf(1, 2, 3, 4, 5) val result = nums.max() println(result)}
5
fun main() { val str = "hello, world" val result = str.filter { it.isLetter() } println(result)}
helloworld
hello,world
hello world