Every mistake makes coding stronger

Report a typo

Imagine that your friend who is studying variables in Kotlin wrote the following program:

fun main() {
    var sum = 0                                                // 1
    val countOdd = 0                                           // 2
    var countEven = 0                                          // 3
    val intsList = listOf<Int>(25, 14, 32, 13, 11, 55, 32, 21) // 4

    for (i in intsList) { // 5
        if (i % 2 == 0) { // 6
            sum += i      // 7
            countEven--   // 8
        } else {          // 9
            countOdd++    // 10
        }
    }
    println(countOdd)     // 11
}

He had to count the number of odd Int's, the number of even Int's, and the sum of even Int's and after that print the sum, but he made some mistakes. Choose the lines that need fixing.

Select one or more options from the list
___

Create a free account to access the full topic