Advertisement
Guest User

Untitled

a guest
Oct 30th, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. public class StringUtil
  2. {
  3. public static String reverseLetters(String str)
  4. {
  5. int len = str.length();
  6. if (len == 1)
  7. return str;
  8. else
  9. {
  10. char lastletter = str.charAt(len-1);
  11. return lastletter + reverseLetters(str.substring(0, len-1));
  12. }
  13. }
  14.  
  15. private static String removePunct(String str){
  16. if (str == null || str.length() < 1){
  17. return str;
  18. }
  19. else {
  20. if (str.length() > 1){
  21. if (str.charAt(0)<48 && str.charAt(0)>=32||str.charAt(0)>=58 && str.charAt(0)<=59){
  22. return removePunct(str.substring(1, str.length()));
  23. }
  24. else{
  25. return str.charAt(0) + removePunct(str.substring(1, str.length()));
  26. }
  27. }
  28. else{
  29. if ( !(str.charAt(0)<48 && str.charAt(0)>=32||str.charAt(0)>=58 && str.charAt(0)<=59)){
  30. return str;
  31. }
  32. else
  33. return "";
  34. }
  35.  
  36. }
  37. }
  38.  
  39. public static boolean checkPalindrome(String str)
  40. {
  41. str = str.toLowerCase();
  42. str = removePunct(str);
  43. if (str.equals(reverseLetters(str)))
  44. {
  45. return true;
  46. }
  47. else
  48. {
  49. return false;
  50. }
  51.  
  52. }
  53.  
  54. public static String translateSentence(String str) {
  55. str = str.trim();
  56. if (str == null || str.length() < 1)
  57. {
  58. return str;
  59. }
  60. //if the string is one word, piglatinate the one word.
  61. if (str.indexOf(' ') == -1)
  62. {
  63. if (checkVowels(str.substring(str.charAt(0))) == true)
  64. {
  65. return str + "yay";
  66. }
  67. if (checkVowels(str) == false)
  68. {
  69. return str + "ay";
  70. }
  71. else
  72. {
  73. return
  74. }
  75. }
  76. //if the string is multiple words, piglatinate the many words.
  77. else
  78. {
  79.  
  80. }
  81. }
  82. private static boolean checkVowels(String str)
  83. {
  84. if (str.indexOf('a') == -1
  85. && str.indexOf('e') == -1
  86. && str.indexOf('i') == -1
  87. && str.indexOf('o') == -1
  88. && str.indexOf('u') == -1
  89. && str.indexOf('A') == -1
  90. && str.indexOf('E') == -1
  91. && str.indexOf('I') == -1
  92. && str.indexOf('O') == -1
  93. && str.indexOf('U') == -1)
  94. return false;
  95. else
  96. return true;
  97. }
  98. private static String getLast(String str)
  99. {
  100. int len = str.length();
  101.  
  102. }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement