Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class StringUtil
- {
- public static String reverseLetters(String str)
- {
- int len = str.length();
- if (len == 1)
- return str;
- else
- {
- char lastletter = str.charAt(len-1);
- return lastletter + reverseLetters(str.substring(0, len-1));
- }
- }
- private static String removePunct(String str){
- if (str == null || str.length() < 1){
- return str;
- }
- else {
- if (str.length() > 1){
- if (str.charAt(0)<48 && str.charAt(0)>=32||str.charAt(0)>=58 && str.charAt(0)<=59){
- return removePunct(str.substring(1, str.length()));
- }
- else{
- return str.charAt(0) + removePunct(str.substring(1, str.length()));
- }
- }
- else{
- if ( !(str.charAt(0)<48 && str.charAt(0)>=32||str.charAt(0)>=58 && str.charAt(0)<=59)){
- return str;
- }
- else
- return "";
- }
- }
- }
- public static boolean checkPalindrome(String str)
- {
- str = str.toLowerCase();
- str = removePunct(str);
- if (str.equals(reverseLetters(str)))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public static String translateSentence(String str) {
- str = str.trim();
- if (str == null || str.length() < 1)
- {
- return str;
- }
- //if the string is one word, piglatinate the one word.
- if (str.indexOf(' ') == -1)
- {
- if (checkVowels(str.substring(str.charAt(0))) == true)
- {
- return str + "yay";
- }
- if (checkVowels(str) == false)
- {
- return str + "ay";
- }
- else
- {
- return
- }
- }
- //if the string is multiple words, piglatinate the many words.
- else
- {
- }
- }
- private static boolean checkVowels(String str)
- {
- if (str.indexOf('a') == -1
- && str.indexOf('e') == -1
- && str.indexOf('i') == -1
- && str.indexOf('o') == -1
- && str.indexOf('u') == -1
- && str.indexOf('A') == -1
- && str.indexOf('E') == -1
- && str.indexOf('I') == -1
- && str.indexOf('O') == -1
- && str.indexOf('U') == -1)
- return false;
- else
- return true;
- }
- private static String getLast(String str)
- {
- int len = str.length();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement