Examveda

The code below is expected to display the numbers from 1 to 10, but it does not. Why?
val seq = sequence { yieldAll(1..20) }
  .filter { it < 11 }
  println(seq)

A. You cannot assign a sequence to a variable

B. To produce result, a sequence must have terminal operation. In this case, it needs a .toList()

C. The .filter{ it < 11 } should be .filter{ it > 11 }

D. The yieldAll(1..20) should be yieldAll(1..10)

Answer: Option B


This Question Belongs to Computer Science >> Kotlin Program

Join The Discussion

Related Questions on Kotlin Program

What is Kotlin?

A. A new version of Java.

B. A JavaScript framework.

C. A statically-typed programming language for the JVM, Android, and browser.

D. A database management system.