Created with <3 with dartpad.dev.
Created
October 31, 2023 01:56
-
-
Save leonus96/583fe603368f09ae80dfec8ccea66922 to your computer and use it in GitHub Desktop.
2. Cuenta_vocales
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Ejercicio 2: Contador de Vocales | |
Escribe una función que cuente cuántas | |
vocales hay en una cadena de texto. | |
*/ | |
void main() { | |
final String cadenaTexto = 'Miguel'; | |
print(cuentaVocales(cadenaTexto)); | |
} | |
int cuentaVocales(String cadena) { | |
int nVocales = 0; | |
for (int i = 0; i < cadena.length; i++) { | |
final String letra = cadena[i]; | |
if (letra == 'a' || | |
letra == 'e' || | |
letra == 'i' || | |
letra == 'o' || | |
letra == 'u') { | |
nVocales++; | |
} | |
} | |
return nVocales; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment