Saltar al contenido

cómo encontrar el número de vocales en una cadena en el ejemplo de código java

Ejemplo: contar vocales en una cadena java

// There are many ways to do it the one i came up with is this:  
int count = 0;
String sentence = "My name is DEATHVADER, Hello World!!! XD";
char[] vowels = {'a', 'e', 'i', 'o', 'u'};
for (char vowel : vowels) 
  for (char letter : sentence.toLowerCase().toCharArray()) 
    if (letter == vowel) count++;
System.out.println("Number of vowels in the given sentence is " + count);

// I have found another easier method if you guyz don't understand this
// but this is also easy xD.
// here you can see another method:
// https://www.tutorialspoint.com/Java-program-to-count-the-number-of-vowels-in-a-given-sentence
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)



Utiliza Nuestro Buscador

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *