@Test public void testIsNotPalindrome() { String[] palindromes = {"ab", "abc", "abbac", "wasitacatsisaw", "steponmypets", "nolemonnomelons"}; for (String str : palindromes) { char[] text = str.toCharArray(); assertFalse(PalindromeHelper.isPalindrome(text, 0, text.length)); } }
public static boolean isPalindrome(char[] text, int start, int end) throws IllegalArgumentException { if (text.length == 0) { return true; } if (start >= end) { throw new IllegalArgumentException(); } int j = end - 1; for (int i = start; i < end; i++) { if (i >= j) { break; } if (text[i] != text[j--]) { return false; } } return true; }
PalindromeHelper { public static boolean isPalindrome(char[] text, int start, int end) throws IllegalArgumentException { if (text.length == 0) { return true; } if (start >= end) { throw new IllegalArgumentException(); } int j = end - 1; for (int i = start; i < end; i++) { if (i >= j) { break; } if (text[i] != text[j--]) { return false; } } return true; } }
PalindromeHelper { public static boolean isPalindrome(char[] text, int start, int end) throws IllegalArgumentException { if (text.length == 0) { return true; } if (start >= end) { throw new IllegalArgumentException(); } int j = end - 1; for (int i = start; i < end; i++) { if (i >= j) { break; } if (text[i] != text[j--]) { return false; } } return true; }  }
PalindromeHelper { public static boolean isPalindrome(char[] text, int start, int end) throws IllegalArgumentException { if (text.length == 0) { return true; } if (start >= end) { throw new IllegalArgumentException(); } int j = end - 1; for (int i = start; i < end; i++) { if (i >= j) { break; } if (text[i] != text[j--]) { return false; } } return true; }  static boolean isPalindrome(char[] text, int start, int end); PalindromeGroup breakIntoPalindromes(char[] text, int start, int end); }
PalindromeHelper { public static boolean isPalindrome(char[] text, int start, int end) throws IllegalArgumentException { if (text.length == 0) { return true; } if (start >= end) { throw new IllegalArgumentException(); } int j = end - 1; for (int i = start; i < end; i++) { if (i >= j) { break; } if (text[i] != text[j--]) { return false; } } return true; }  static boolean isPalindrome(char[] text, int start, int end); PalindromeGroup breakIntoPalindromes(char[] text, int start, int end);  }