Kotlin Basic QuizBy Parvesh Sandila / September 15, 2023 Welcome to your Kotlin Basic Questions Name Email 1. What is the output of the following Kotlin program? fun main() { var fib1 = 0 var fib2 = 1 for (i in 1..10) { print("$fib1, ") val next = fib1 + fib2 fib1 = fib2 fib2 = next }} 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, This program will not compile. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, None 2. In Kotlin, which collection type represents an ordered list of elements? List Set Array Map None 3. In Kotlin, what is the purpose of the "fun" keyword? It defines a new data type It specifies a variable's data type It declares a function It stands for "funny" None 4. Which Kotlin feature helps prevent null pointer exceptions? Star operator (*) Arrow operator (->) Unicorn operator (->>) Elvis operator (?:) None 5. How can you define a read-only property in Kotlin? Using the "get" keyword Using the "var" keyword Using the "val" keyword Using the "readonly" keyword None 6. Given the following Kotlin program, what will be the value of result? val x = 5val y = 3val result = x * y 15 3 8 53 None 7. What does the following Kotlin program do? fun main() { var n = 10 var factorial = 1 while (n > 0) { factorial *= n n-- } println(factorial)} Calculates the factorial of 10. Calculates the sum of the first 10 numbers. Prints the first 10 prime numbers. Prints the numbers from 10 to 1 in reverse order. None 8. How do you declare a nullable variable in Kotlin? Using the ? operator Using the * symbol Using the # symbol Using the ! operator None 9. What is the range operator used to create a range of numbers in Kotlin? -> -- :: .. None 10. 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)} 10 120 3 15 None 11. Given the following Kotlin program, what will be the value of max? val num1 = 10val num2 = 25val num3 = 15val max = if (num1 >= num2 && num1 >= num3) num1else if (num2 >= num1 && num2 >= num3) num2else num3 15 25 10 30 None 12. What is the Kotlin equivalent of a "for loop" in other programming languages? repeat loop foreach loop for-in loop while loop None 13. 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")} This program will not compile. After swapping: a = 10, b = 5 After swapping: a = 5, b = 10 After swapping: a = 0, b = 0 None 14. What is the output of the following Kotlin program? fun main() { var sum = 0 for (i in 1..10) { sum += i } println(sum) } 10 55 15 45 None 15. What is the entry point of a Kotlin program? run() method execute() function main() function start() function None 1 out of 15