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