Which code snippet correctly shows a for loop using a range to display "1 2 3 4 5 6"?
A. for(z in 1..7) println("$z ")
B. for(z in 1..6) print("$z ")
C. for(z in 1 to 6) print("$z ")
D. for(z in 1..7) print("$z ")
Select an option to see the answer and solution.
Which snippet correctly shows setting the variable max to whichever variable holds the greatest value, a or b, using idiomatic Kotlin?
A. val max3 = a.max(b)
B. val max = a > b ? a : b
C. val max = if (a > b) a else b
D. if (a > b) max = a else max = b
Select an option to see the answer and solution.
Which lifecycle method should you override to pause the simulation when the app is not on the screen?
A. onDestroy()
B. onStop()
C. onPause()
D. onSaveInstanceState()
Select an option to see the answer and solution.
Your function is passed by a parameter obj of type Any. Which code snippet shows a way to retrieve the original type of obj, including package information?
A. obj.classInfo()
B. obj.typeInfo()
C. obj::class.simpleName
D. obj::class
Select an option to see the answer and solution.
Which function changes the value of the element at the current iterator location?
A. change()
B. modify()
C. set() (reference)
D. assign()
Select an option to see the answer and solution.
The Kotlin .. operator can be written as which function?
A. a.from(b)
B. a.range(b)
C. a.rangeTo(b)
D. a.to(b)
Select an option to see the answer and solution.
How can you create a variable with the floating number 2.8?
A. num = 2.8 float
B. val num = 2.8
C. float num = 2.8
D. double num = 2.8
Select an option to see the answer and solution.
How can you create a range of numbers between 5 and 15 in Kotlin?
A. for (x in 5 to 15)
B. for (5..15)
C. for (5 to 15)
D. for (x in 5..15)
Select an option to see the answer and solution.
How to access the elements of an array in Kotlin?
A. array.get(index)
B. array[index]
C. array(index)
D. None of these
Select an option to see the answer and solution.
The actual function for getting the string length in Kotlin language is?
A. lengthof(str)
B. string(length)
C. str.length
D. None of the above options
Select an option to see the answer and solution.
How do you declare a String in Kotlin?
A. val str: String = "Hello, World!"
B. String str = "Hello, World!"
C. val str = String("Hello, World!")
D. String str = new String("Hello, World!")
Select an option to see the answer and solution.
In Kotlin, how do you compare two Strings for equality?
A. str1 == str2
B. str1.equals(str2)
C. Both A and B
D. str1.sameAs(str2)
Select an option to see the answer and solution.
How can you create a variable with the numeric value 5?
A. num = 5 int
B. int num = 5
C. num = 5
D. val num = 5
Select an option to see the answer and solution.
Which operator is used to add together two values?
A. The ADD keyword
B. The * sign
C. The & sign
D. The + sign
Select an option to see the answer and solution.
Which operator can be used to compare two values?
Select an option to see the answer and solution.
Select the method to pass data back from an activity in Android for Kotlin
A. startActivity()
B. startActivityForResult()
C. ActivityForResult()
D. None of these
Select an option to see the answer and solution.
Which symbol is used for string templates/interpolation?
Select an option to see the answer and solution.
What is the correct way to create an object called myObj of MyClass?
A. Main myObj = new MyClass();
B. MyClass.new myObj
C. val myObj = MyClass()
D. None of these
Select an option to see the answer and solution.
How do you declare a nullable variable in Kotlin?
A. var name: String?
B. var name: String
C. var name: String = null
D. String name = null
Select an option to see the answer and solution.
How do you define a function in Kotlin?
A. fun myFunction() {}
B. def myFunction() {}
C. function myFunction() {}
D. fun = myFunction() {}
Select an option to see the answer and solution.