Problem05 { public static String longestPalindrome(final String input) { String[] chars = input.split(""); String palindrome = null; for (int i = 0; i < chars.length; i++) { String left = chars[i]; for (int j = chars.length - 1; j > i; j--) { String right = chars[j]; if (Objects.equals(left, right)) { String first = input.substring(i, j + 1); if (Objects.equals(first, reverse(first))) { if (palindrome == null || first.length() > palindrome.length()) { palindrome = first; } } } } } return palindrome; }  static String longestPalindrome(final String input); static String longestPalindrome1(final String input);  }
@Test public void shouldDetectLongestPalindrome() throws Exception { final String input = "saasdcjkbkjnjnnknvjfknjnfjkvnjkfdnvjknfdkvjnkjfdnvkjnvjknjkgnbjkngkjvnjkgnbvkjngfreyh67ujrtyhytju789oijtnuk789oikmtul0oymmmmmmmmmmmmmmmm"; String l = Problem05.longestPalindrome(input); assertThat(l, equalTo("mmmmmmmmmmmmmmmm")); }