davegimo

donato2

Mar 15th, 2021
26
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class WordInspector{
  2.  
  3. private String word;
  4. public static final char[] VOWELS = {'a','e','i','o','u'};
  5.  
  6. public WordInspector(String word) {
  7. this.word = word;
  8. }
  9.  
  10. public String getWord() {
  11. return this.word;
  12. }
  13.  
  14. public void setWord(String word) {
  15. this.word = word;
  16. }
  17.  
  18. public int countVowels() {
  19. int conta = 0;
  20.  
  21. for (int i = 0; i < this.word.length(); i++) {
  22. for (int j = 0; j < 5; j++) {
  23. if (this.word.charAt(i) == VOWELS[j]){
  24. conta++;
  25. break;
  26. }
  27. }
  28. }
  29. return conta;
  30. }
  31.  
  32.  
  33.  
  34. public static void main(String []args){
  35. WordInspector test = new WordInspector("test");
  36. System.out.println(test.countVowels());
  37. }
  38. }
RAW Paste Data