Advertisement
Guest User

Untitled

a guest
Dec 7th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.37 KB | None | 0 0
  1. public class SameEnds {
  2.    
  3.     public static void main (String args[]) {
  4.  
  5.         String test = "abXYab";
  6.         int testLength = test.length();
  7.         String longestSub = " ";
  8.  
  9.         for (int i = 0; i < (testLength / 2); i++) {
  10.             if (test.substring(i).equals(test.substring(testLength - i)))
  11.                 longestSub = test.substring(i);
  12.         }
  13.  
  14.         System.out.println(longestSub);
  15.  
  16.     }
  17.    
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement