Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class WordInspector{
- private String word;
- public static final char[] VOWELS = {'a','e','i','o','u'};
- public WordInspector(String word) {
- this.word = word;
- }
- public String getWord() {
- return this.word;
- }
- public void setWord(String word) {
- this.word = word;
- }
- public int countVowels() {
- int conta = 0;
- for (int i = 0; i < this.word.length(); i++) {
- for (int j = 0; j < 5; j++) {
- if (this.word.charAt(i) == VOWELS[j]){
- conta++;
- break;
- }
- }
- }
- return conta;
- }
- public static void main(String []args){
- WordInspector test = new WordInspector("test");
- System.out.println(test.countVowels());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement