Advertisement
Guest User

Untitled

a guest
Oct 30th, 2014
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1.  
  2. /**
  3. * Write a description of class Strings here.
  4. *
  5. * @author (your name)
  6. * @version (a version number or a date)
  7. */
  8.  
  9. import java.util.ArrayList;
  10.  
  11. public class StringHelp
  12. {
  13. public static String alphabetize(String word1, String word2, String word3)
  14. {
  15. String w1 = word1;
  16. String w2 = word2;
  17. String w3 = word3;
  18. boolean swapped = false;
  19.  
  20. do {
  21. swapped = false;
  22. if (w2.compareTo(w1) <= 0) {
  23. String tmp = w2;
  24. w2 = w1;
  25. w1 = tmp;
  26. swapped = true;
  27. }
  28. if (w3.compareTo(w2) < 0) {
  29. String tmp = w3;
  30. w3 = w2;
  31. w2 = tmp;
  32. swapped = true;
  33. }
  34. } while(swapped);
  35.  
  36. return w1+", "+w2+", "+w3;
  37. }
  38.  
  39. public static String pigLatin(String word)
  40. {
  41. char a = word.charAt(0);
  42. return word.substring(1,word.length())+a+"ay";
  43. }
  44.  
  45. public static String firstLast(String lastFirst)
  46. {
  47. int loc = lastFirst.indexOf(",");
  48. String last = lastFirst.substring(0,loc);
  49. return lastFirst.substring(loc+2)+" "+last;
  50. }
  51.  
  52. public static int countChar(String phrase, char c)
  53. {
  54. phrase = phrase.toLowerCase();
  55. int len = phrase.length();
  56. int count = 0;
  57.  
  58. for(int i = 0; i < len; i++)
  59. {
  60. if(phrase.charAt(i) == c)
  61. {
  62. count++;
  63. }
  64. }
  65.  
  66. return count;
  67. }
  68.  
  69. public static String reverse(String phrase)
  70. {
  71. int len = phrase.length();
  72. char a = 'z';
  73. String np = "";
  74. String tmp = "";
  75.  
  76. for (int i = len-1; i >= 0; i--)
  77. {
  78. tmp = np;
  79. a = phrase.charAt(i);
  80. np = tmp+a;
  81. }
  82.  
  83. return np;
  84. }
  85.  
  86. public static String compact(String phrase)
  87. {
  88. ArrayList<String> word = new ArrayList<String>();
  89.  
  90. int len = phrase.length();
  91. char a = 'a';
  92. for(int x = 0; x < len; x++)
  93. {
  94. a = phrase.charAt(x);
  95.  
  96. if(a == ' ')
  97. word.add("");
  98. else
  99. word.add(""+a);
  100. }
  101.  
  102. String tmp = "";
  103. for(String s : word)
  104. {
  105. tmp = tmp + s;
  106. }
  107.  
  108. return tmp;
  109. }
  110.  
  111. public static boolean isPalindrome(String phrase)
  112. {
  113. if(reverse(phrase) == phrase)
  114. return true;
  115. else
  116. return false;
  117.  
  118. }
  119.  
  120. public static boolean starts(String phrase)
  121. {
  122. String[] array = {"a", "e","i","o", "u"};
  123. int len = phrase.length();
  124.  
  125. for(int y = 0; y < 5; y++)
  126. {
  127. if(phrase.startsWith(array[y]))
  128. return true;
  129. }
  130.  
  131. return false;
  132. }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement