package lab_6_sol; public class MyString { public static String reversString(String str) { String s = " "; for (int i = str.length() - 1; i >= 0; i--) { s += str.charAt(i); } return s; } public static boolean isPalindrome(String str) { str = filter(str); return (str.equalsIgnoreCase(reversString(str))); } private static String filter(String str) { StringBuilder str2 = new StringBuilder(); for (int i = 0; i < str.length(); i++) { if (Character.isLetterOrDigit(str.charAt(i))) { str2.append(str.charAt(i)); } } return str2.toString(); } public static String shortHnaded(String str) { str = str.replaceAll("and", "&"); str = str.replaceAll("to", "2"); str = str.replaceAll("you", "U"); str = str.replaceAll("for", "4"); String[] s = str.split(""); for (int i = 0; i < s.length; i++) { if (s[i].compareToIgnoreCase("I") == 0 || s[i].compareToIgnoreCase("u") == 0) { continue; } else { str = str.replaceAll("[aeiouAEIOU]", ""); } } return str; } public static int numberOfSentences(String str) { String[] s = str.split("[.,!?]"); return s.length; } public static int numberOfWords(String str) { String[] s = str.split(" "); int counter = s.length; for (int i = 0; i < s.length; i++) { if (s[i].length() < 3) { counter--; } } return counter; } }