Skip to content

Instantly share code, notes, and snippets.

@Minikloon
Created October 27, 2016 06:00
Show Gist options
  • Save Minikloon/80d2e605013ee393900fe2808a0bb7b9 to your computer and use it in GitHub Desktop.
Save Minikloon/80d2e605013ee393900fe2808a0bb7b9 to your computer and use it in GitHub Desktop.
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public class Main {
private static Set<Character> vowels = new HashSet<>(Arrays.asList('a', 'e', 'i', 'o', 'u'));
public static void main(String[] args) {
String input = "abcdefghijklmnopqrstuvwxyz";
int vowelsCount = countVowels(input);
System.out.println("There are " + vowelsCount + " vowels in '" + input + "'");
}
private static int countVowels(String str) {
int count = 0;
for(int i = 0; i < str.length(); ++i) {
if(vowels.contains(str.charAt(i)))
++count;
}
return count;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment