fork download
  1. public final class Main {
  2. public static void main(String[] args) {
  3. String input = "FourscoreandsevenyearsagoourfaathersbroughtforthonthiscontainentanewnationconceivedinzLibertyanddedicatedtothepropositionthatallmenarecreatedequalNowweareengagedinagreahtcivilwartestingwhetherthatnaptionoranynartionsoconceivedandsodedicatedcanlongendureWeareqmetonagreatbattlefiemldoftzhatwarWehavecometodedicpateaportionofthatfieldasafinalrestingplaceforthosewhoheregavetheirlivesthatthatnationmightliveItisaltogetherfangandproperthatweshoulddothisButinalargersensewecannotdedicatewecannotconsecratewecannothallowthisgroundThebravelmenlivinganddeadwhostruggledherehaveconsecrateditfaraboveourpoorponwertoaddordetractTgheworldadswfilllittlenotlenorlongrememberwhatwesayherebutitcanneverforgetwhattheydidhereItisforusthelivingrathertobededicatedheretotheulnfinishedworkwhichtheywhofoughtherehavethusfarsonoblyadvancedItisratherforustobeherededicatedtothegreattdafskremainingbeforeusthatfromthesehonoreddeadwetakeincreaseddevotiontothatcauseforwhichtheygavethelastpfullmeasureofdevotionthatweherehighlyresolvethatthesedeadshallnothavediedinvainthatthisnationunsderGodshallhaveanewbirthoffreedomandthatgovernmentofthepeoplebythepeopleforthepeopleshallnotperishfromtheearth";
  4. String match = "";
  5.  
  6. StringBuilder stringBuilder = new StringBuilder();
  7.  
  8. for(int i = 0, j = 0; i < input.length() || j < input.length(); i += j + 1 == input.length() ? 1 : 0, j = j + 1 == input.length() ? i : j + 1) {
  9. String string1 = input.substring(i, j);
  10.  
  11. stringBuilder.delete(0, stringBuilder.length());
  12. stringBuilder.append(string1);
  13. stringBuilder.reverse();
  14.  
  15. String string2 = stringBuilder.toString();
  16.  
  17. if(string1.equals(string2) && string1.length() > match.length()) {
  18. match = string1;
  19. }
  20. }
  21.  
  22. System.out.println("The match is \"" + match + "\".");
  23. }
  24. }
Success #stdin #stdout 1.64s 380224KB
stdin
Standard input is empty
stdout
The match is "ranynar".