fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String str = "Airplane";
  13. boolean lastCharacterWasVowel = false;
  14. boolean doubleVowel = false;
  15. int syllableCount = 0;
  16. for(int i = 0; i< str.length(); i++){
  17. if ((str.charAt(i) == 'a' || str.charAt(i) == 'A'
  18. || str.charAt(i) == 'e' || str.charAt(i) == 'E'
  19. || str.charAt(i) == 'i' || str.charAt(i) == 'I'
  20. || str.charAt(i) == 'o' || str.charAt(i) == 'O'
  21. || str.charAt(i) == 'u' || str.charAt(i) == 'U'
  22. || str.charAt(i) == 'y' || str.charAt(i) == 'Y')){
  23. if (lastCharacterWasVowel) {
  24. syllableCount++;
  25. doubleVowel = true;
  26. } else {
  27. doubleVowel = false;
  28. }
  29. lastCharacterWasVowel = true;
  30. } else {
  31. if (lastCharacterWasVowel && !doubleVowel)
  32. syllableCount++;
  33. lastCharacterWasVowel = false;
  34. }
  35. }
  36. if (lastCharacterWasVowel) {
  37. if (str.charAt(str.length() - 1) != 'e' && str.charAt(str.length() - 1) != 'E')
  38. syllableCount++;
  39. }
  40. System.out.println("Count: " + Math.max(1, syllableCount));
  41. }
  42. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
Count: 2