/**
 * This exercise aims to find the number of occurrences of a specific character in a given string using nested loops.
 *
 * @param string a string in which we want to find the occurrences of a character
 * @param char the character to count occurrences of
 * @return an integer representing the number of occurrences of the character
 *
 * Example:
 * countCharacters("Hello, World!", 'l') // Output: 3
 * countCharacters("banana", 'a') // Output: 3
 */
fun countCharacters(string: String, char: Char): Int {

    var count = 0  // initialize the counter variable
    
    // Iterate through each character in the string
    for (i in string.indices) {
        
        // Loop through each character again for comparison
        for (j in i until string.length) {
            
            // Check if the characters match
            if (string[j] == char) {
                count++  // increment the counter
            }
        }
    }
    
    return count
}
/**
 * This exercise aims to find the number of occurrences of a specific character in a given string using nested loops.
 *
 * @param string a string in which we want to find the occurrences of a character
 * @param char the character to count occurrences of
 * @return an integer representing the number of occurrences of the character
 *
 * Example:
 * countCharacters("Hello, World!", 'l') // Output: 3
 * countCharacters("banana", 'a') // Output: 3
 */
fun countCharacters(string: String, char: Char): Int {
/**
 * This exercise aims to find the number of occurrences of a specific character in a given string using nested loops.
 *
 * @param string a string in which we want to find the occurrences of a character
 * @param char the character to count occurrences of
 * @return an integer representing the number of occurrences of the character
 *
 * Example:
 * countCharacters("Hello, World!", 'l') // Output: 3
 * countCharacters("banana", 'a') // Output: 3
 */
fun countCharacters(string: String, char: Char): Int {

    var count = 0  // initialize the counter variable
    
    // Iterate through each character in the string
    for (i in string.indices) {
        
        // Loop through each character again for comparison
        for (j in i until string.length) {
            
            // Check if the characters match
            if (string[j] == char) {
                count++  // increment the counter
            }
        }
    }
    
    return count
}