Stiven Palate

Generation

generate functionMon, 12 Jun 2023

Genere un método el cual acepte como argumento una matriz de cadenas y genere otra matriz del mismo orden en donde almacene en cada posición la cantidad de vocales que contiene cada palabra en la misma posición

// Java public static String[] countVowels(String[] words) { String[] result = new String[words.length]; for(int i = 0; i < words.length; i++) { String word = words[i]; int vowels = 0; for(int j = 0; j < word.length(); j++) { char letter = word.charAt(j); if(letter == 'a' || letter == 'e' || letter == 'i' || letter == 'o' || letter == 'u') { vowels++; } } result[i] = vowels.toString(); } return result; } // Ruby def count_vowels(words) words.map do |word| word.count('aeiou') end end // Python def countVowels(words): return [sum(1 for c in word if c in 'aeiou') for word in words]

Questions about programming?Chat with your personal AI assistant