Comprehension

Report a typo

Look at the following code:

fun main() {

    val input = "abracadabra"
    val count = countCharacterA(input)
    println("$count")
}

fun countCharacterA(charSeq: CharSequence): Int {
    var count = 0
    for (element in charSeq) {
        if (element == 'a') {
            count++
        }
    }
    return count
}

What is the output of the program?

Enter a number
___

Create a free account to access the full topic