Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Write a description of class Strings here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- import java.util.ArrayList;
- public class StringHelp
- {
- public static String alphabetize(String word1, String word2, String word3)
- {
- String w1 = word1;
- String w2 = word2;
- String w3 = word3;
- boolean swapped = false;
- do {
- swapped = false;
- if (w2.compareTo(w1) <= 0) {
- String tmp = w2;
- w2 = w1;
- w1 = tmp;
- swapped = true;
- }
- if (w3.compareTo(w2) < 0) {
- String tmp = w3;
- w3 = w2;
- w2 = tmp;
- swapped = true;
- }
- } while(swapped);
- return w1+", "+w2+", "+w3;
- }
- public static String pigLatin(String word)
- {
- char a = word.charAt(0);
- return word.substring(1,word.length())+a+"ay";
- }
- public static String firstLast(String lastFirst)
- {
- int loc = lastFirst.indexOf(",");
- String last = lastFirst.substring(0,loc);
- return lastFirst.substring(loc+2)+" "+last;
- }
- public static int countChar(String phrase, char c)
- {
- phrase = phrase.toLowerCase();
- int len = phrase.length();
- int count = 0;
- for(int i = 0; i < len; i++)
- {
- if(phrase.charAt(i) == c)
- {
- count++;
- }
- }
- return count;
- }
- public static String reverse(String phrase)
- {
- int len = phrase.length();
- char a = 'z';
- String np = "";
- String tmp = "";
- for (int i = len-1; i >= 0; i--)
- {
- tmp = np;
- a = phrase.charAt(i);
- np = tmp+a;
- }
- return np;
- }
- public static String compact(String phrase)
- {
- ArrayList<String> word = new ArrayList<String>();
- int len = phrase.length();
- char a = 'a';
- for(int x = 0; x < len; x++)
- {
- a = phrase.charAt(x);
- if(a == ' ')
- word.add("");
- else
- word.add(""+a);
- }
- String tmp = "";
- for(String s : word)
- {
- tmp = tmp + s;
- }
- return tmp;
- }
- public static boolean isPalindrome(String phrase)
- {
- if(reverse(phrase) == phrase)
- return true;
- else
- return false;
- }
- public static boolean starts(String phrase)
- {
- String[] array = {"a", "e","i","o", "u"};
- int len = phrase.length();
- for(int y = 0; y < 5; y++)
- {
- if(phrase.startsWith(array[y]))
- return true;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement