Created
October 27, 2016 06:00
-
-
Save Minikloon/80d2e605013ee393900fe2808a0bb7b9 to your computer and use it in GitHub Desktop.
This file contains 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
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