(Coderbyte) Vowel Count - Solução
Have the function VowelCount(str) take the str
string parameter being passed and return the number of vowels the string contains (ie. "All cows eat grass" would return 5). Do not count y as a vowel for this challenge.
Solução:
import java.util.*;
import java.io.*;
class Function {
int VowelCount(String str) {
final String VOWEL = "aeiouAEIOU";
int counter = 0;
for (int i = 0; i < str.length(); i++) {
if (VOWEL.indexOf(str.charAt(i)) > -1) {
counter++;
}
}
return counter;
}
public static void main (String[] args) {
// keep this function call here
Scanner s = new Scanner(System.in);
Function c = new Function();
System.out.print(c.VowelCount(s.nextLine()));
}
}
Solução:
import java.util.*;
import java.io.*;
class Function {
int VowelCount(String str) {
final String VOWEL = "aeiouAEIOU";
int counter = 0;
for (int i = 0; i < str.length(); i++) {
if (VOWEL.indexOf(str.charAt(i)) > -1) {
counter++;
}
}
return counter;
}
public static void main (String[] args) {
// keep this function call here
Scanner s = new Scanner(System.in);
Function c = new Function();
System.out.print(c.VowelCount(s.nextLine()));
}
}
Comments
Post a Comment