Advertisement
gluten_free_feeling

PigLatin

Nov 12th, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. public static String pigLatin(String word)
  2. {
  3. word = word.toLowerCase();
  4. int length = word.length();
  5. int a = word.indexOf("a");
  6. int e = word.indexOf("e");
  7. int i = word.indexOf("i");
  8. int o = word.indexOf("o");
  9. int u = word.indexOf("u");
  10.  
  11. if(a == -1 && e == -1 && i == -1 && o == -1 && u == -1)
  12. return word + "ay";
  13. else if(word.charAt(0) == 'a' || word.charAt(0) == 'e' || word.charAt(0) == 'i' || word.charAt(0) == 'o' || word.charAt(0) == 'u')
  14. return word + "yay";
  15. else
  16. {
  17. int startInt = StringUtil.firstVowel(word);
  18. String start = word.substring(0, startInt);
  19. String end = word.substring(startInt, length);
  20. if(word.substring(0,1) == (word.substring(0,2)).toUpperCase())
  21. return ((word.substring(0,1)).toUpperCase() + end.substring(1) + start.toLowerCase());
  22. else
  23.  
  24. return end + start;
  25.  
  26. }
  27. }
  28. public static int firstVowel (String word)
  29. {
  30. int length = word.length();
  31. int a = word.indexOf("a");
  32. int e = word.indexOf("e");
  33. int i = word.indexOf("i");
  34. int o = word.indexOf("o");
  35. int u = word.indexOf("u");
  36. int number = 1;
  37. if(word.charAt(1) == 'a' || word.charAt(1) == 'e' || word.charAt(1) == 'i' || word.charAt(1) == 'o' || word.charAt(1) == 'u')
  38. return number ;
  39. else
  40. return firstVowel(word.substring(1)) + number++;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement