
Kotlin Quiz - Find the Output

Quiz
•
Computers
•
Professional Development
•
Hard
Nisha V
FREE Resource
30 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the output of the following code?
fun square(num: Int): Int { return num * num }
fun main() { val result = square(5) println("The square of 5 is: $result") }
The square of 5 is: 10
25
The square of 5 is: 25
square(5)
Answer explanation
The function 'square' calculates the square of the input number. When 'square(5)' is called, it returns 25. The output statement then prints 'The square of 5 is: 25', making the correct choice 'The square of 5 is: 25'.
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the output of the following code? fun factorial(n: Int): Int { return if (n == 0) 1 else n * factorial(n - 1) } fun main() { val num = 5 val result = factorial(num) println("Factorial of $num is $result") }
120
25
Factorial of 5 is 120
5
Answer explanation
The code calculates the factorial of 5 using recursion. The factorial of 5 is 5 * 4 * 3 * 2 * 1 = 120. The output statement prints 'Factorial of 5 is 120', making the correct choice 'Factorial of 5 is 120'.
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the output of the following code? fun add(a: Int, b: Int): Int = a + b fun calculate(x: Int, y: Int, operation: (Int, Int) -> Int): Int { return operation(x, y) } fun main() { val result = calculate(10, 5, ::add) println("Result: $result") }
10
15
Result: 15
Error
Answer explanation
The function 'add' takes two integers and returns their sum. In 'calculate', 'operation' is passed as '::add'. Thus, 'calculate(10, 5, ::add)' computes 10 + 5, resulting in 15. The output is 'Result: 15'.
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the output of the following code? fun main() { val square = { x: Int -> x * x } val result = square(6) println("Square is: $result") }
36
6
Square is: 36
Error
Answer explanation
The code defines a lambda function 'square' that calculates the square of an integer. When called with 6, it returns 36. The result is printed as 'Square is: 36', making this the correct output.
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the output of the following code? inline fun greet(block: () -> Unit) { println("Before greeting") block() println("After greeting") } fun main() { greet { println("Hello, Nisha!") } }
Before greeting Hello, Nisha! After greeting
Hello, Nisha! After greeting
Only Before greeting
Compilation Error
Answer explanation
The code defines a function 'greet' that prints a message before and after executing a block of code. When 'greet' is called in 'main', it prints 'Before greeting', executes the block (printing 'Hello, Nisha!'), and then prints 'After greeting'. Thus, the output is 'Before greeting Hello, Nisha! After greeting'.
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the output of the following code? val age = 18 if (age < 13) { println("Child") } else if (age in 13..17) { println("Teenager") } else { println("Adult") }
Teenager
Adult
Child
Error
Answer explanation
The variable 'age' is set to 18. The first condition checks if age is less than 13 (false), the second checks if age is between 13 and 17 (false). Thus, it goes to the else block, printing 'Adult', which is the correct answer.
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the output of the following code? val day = 3 when (day) { 1 -> println("Sunday") 2 -> println("Monday") 3 -> println("Tuesday") else -> println("Invalid day") }
Monday
Tuesday
3
Invalid day
Answer explanation
The variable 'day' is set to 3. The 'when' expression checks the value of 'day' and matches it to the case for 3, which prints 'Tuesday'. Therefore, the output of the code is 'Tuesday'.
Create a free account and access millions of resources
Similar Resources on Wayground
29 questions
AI Selection Test

Quiz
•
Professional Development
30 questions
Pretest Konsep Sistem Informasi

Quiz
•
University - Professi...
25 questions
OCS752 Introduction to C Programming

Quiz
•
Professional Development
30 questions
Java Programming Fundamentals

Quiz
•
Professional Development
25 questions
C second module quiz

Quiz
•
Professional Development
25 questions
C module 1 second quiz

Quiz
•
Professional Development
27 questions
Python Quiz

Quiz
•
Professional Development
30 questions
Python - Basic Data, Structure, and Concepts

Quiz
•
Professional Development
Popular Resources on Wayground
10 questions
SR&R 2025-2026 Practice Quiz

Quiz
•
6th - 8th Grade
30 questions
Review of Grade Level Rules WJH

Quiz
•
6th - 8th Grade
6 questions
PRIDE in the Hallways and Bathrooms

Lesson
•
12th Grade
10 questions
Lab Safety Procedures and Guidelines

Interactive video
•
6th - 10th Grade
10 questions
Nouns, nouns, nouns

Quiz
•
3rd Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
11 questions
All about me

Quiz
•
Professional Development
15 questions
Subtracting Integers

Quiz
•
7th Grade
Discover more resources for Computers
11 questions
All about me

Quiz
•
Professional Development
10 questions
How to Email your Teacher

Quiz
•
Professional Development
5 questions
Setting goals for the year

Quiz
•
Professional Development
14 questions
2019 Logos

Quiz
•
Professional Development
6 questions
GUM Chart Scavenger Hunt

Quiz
•
Professional Development
10 questions
How to Email your Teacher

Quiz
•
Professional Development
20 questions
Employability Skills

Quiz
•
Professional Development