Finding the longest repeated substring in a string
Off-by-one error

You have an off-by-one error in the innermost while loop: for input string "aa", this will not reach length 1, and give empty string as the result, which is incorrect. 

I looked at this loop with suspicion, because I noticed that it checks the string bound in the second condition. The more natural code organization is to check the bound first, and then the second condition &amp;&amp;-ed to the first will be safe. 

I suggest to rearrange that way, and for that you will need to rethink and verify all the indexes and ranges there. Which can be pretty hard to get right. So at this point, before touching anything, I suggest to add a bunch of Junit tests first, try to cover all the corner cases.

More bugs

I tried a bunch of random examples, and the program gives incorrect results:


"abac" -> "ab"
"abcac" -> "ab"
"abcba" -> "bc"


As I suggested in the previous point,
it will be good to add Junit tests to verify the logic.

Longest repeated substring problem

Quoting from Wikipedia:


  This problem can be solved in linear time and space by building a suffix tree for the string, and finding the deepest internal node in the tree. Depth is measured by the number of characters traversed from the root. 


I think you should look into that and abandon your current implementation.