1. How do you declare a nullable variable in Kotlin?
2. What is the range operator used to create a range of numbers in Kotlin?
3. What is the output of the following Kotlin program?
fun main() {
val numbers = arrayOf(1, 2, 3, 4, 5)
val sum = numbers.reduce { acc, num -> acc + num }
println(sum)
}
4. What is the output of the following Kotlin program?
fun main() {
var a = 5
var b = 10
a = b.also { b = a }
println("After swapping: a = $a, b = $b")
}
5. In Kotlin, which collection type represents an ordered list of elements?
6. In Kotlin, what keyword is used to declare a function?
7. Given the following Kotlin program, what will be the value of max?
val num1 = 10
val num2 = 25
val num3 = 15
val max = if (num1 >= num2 && num1 >= num3) num1
else if (num2 >= num1 && num2 >= num3) num2
else num3
8. Which Kotlin feature helps prevent null pointer exceptions?
9. In Kotlin, what is the purpose of the "fun" keyword?
10. What does the following Kotlin program do?
fun main() {
var n = 10
var factorial = 1
while (n > 0) {
factorial *= n
n--
}
println(factorial)
}
11. Given the following Kotlin program, what will be the value of result?
val x = 5
val y = 3
val result = x * y
12. What is the entry point of a Kotlin program?
13. How can you define a read-only property in Kotlin?
14. In Kotlin, which keyword is used to declare a variable that cannot be reassigned?
15. What is the output of the following Kotlin program?
fun main() {
var sum = 0
for (i in 1..10) {
sum += i
}
println(sum)
}