public class MyClass {
private static String GetLongestSubstring(String str) {
int start = 0, end = 0, max = 0;
int size = str.length();
for (int i = 0; i < size - 1; i++) {
for (int j = i + 1; j < size; j++) {
if (str.charAt(i) == str.charAt(j)) {
int temp = Math.abs(j - i - 1);
if (temp > max) {
max = temp;
start = i + 1;
end = j;
}
}
}
}
return str.substring(start, end);
}
public static void main(String args[]) {
String str = "zXoDjavaprogrammingDkmq";
String result = GetLongestSubstring(str);
System.out.print(result);
}
}
/*
run:
javaprogramming
*/