Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- /**
- *
- * @author Erieze
- */
- public class Main {
- /**
- * Check if the given {@code text} is a Palindrome String.
- * <p>
- * Punctuation and whitespace are ignored.
- *
- * @param text A String
- * @return True if text is palindrome, otherwise false
- */
- private static boolean isPalindrome(String text) {
- return removePunc(text).equalsIgnoreCase(
- removePunc(new StringBuilder(text).reverse().toString()));
- }
- /**
- * Removes punctuation from String.
- *
- * @param text A String
- * @return String without punctuation
- */
- private static String removePunc(String text) {
- return text.replaceAll("\\s|(?![@,&])\\p{Punct}", "");
- }
- public static void main(String[] args) throws IOException {
- final String text = "Are we not pure? \"No sir!\" Panama's moody Noriega brags. \"It is garbage!\" Irony dooms a man; a prisoner up to new era.";
- System.out.println("isPalindrome(" + text + ")? " + isPalindrome(text));
- final String s = "QWERTY";
- String result = "";
- for (char ch : s.toCharArray()) {
- if (ch == 'Q')
- result += "A";
- else if (ch == 'W')
- result += "B";
- else if (ch == 'E')
- result += "C";
- else if (ch == 'R')
- result += "D";
- else if (ch == 'T')
- result += "E";
- else if (ch == 'Y')
- result += "F";
- }
- System.out.println(Integer.parseInt(result, 16));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment