1. Write a method which checks if a String is a palindrome and returns a boolean value. with differing inputs for handling a Palindromic sentence.
Anonymous
"A man a plan, a canal, Panama!" is the input and is also a Palindromic sentence Amanaplanacanalpanama - all characters joined. boolean isPalindrome(String input) { if(input.isEmpty()) { return true; } else { String palindrome = input.replaceAll("[,^$%!]", ""); trimWhiteSpaces(palindrome); int length = palindrome.length(); for(int i = 0; i < (length/2); ++i) { if(palindrome.toLowerCase().charAt(i) != palindrome.toLowerCase().charAt(length-i-1)) { return false; } } return true; } } String trimWhiteSpaces(String s) { String inputWithNoSpaces = s.replaceAll("\\s",""); char[] inputStringArray = s.toCharArray(); StringBuffer inputStringBuffer = new StringBuffer(); for(int i = 0; i < inputStringArray.length; ++i) { if(inputStringArray[i] != '' && inputStringArray[i] != '\t') { inputStringBuffer.append(inputStringArray[i])); } } } This is was my solution, with a minor bug and it worked when traced.
Check out your Company Bowl for anonymous work chats.