I am writing a java program to use a for
loop and substrings to return a palindrome, but I'm confused on what to put in the substring?
This is the code I used, and the error I received:
String str2 = "";
for(int k = 2; k < sentence.length(); k++)
{
String str3 = "";
str3 = str2.substring(k , sentence.length()-1);
......
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: begin 2, end 22, length 0
Does anyone know how to fix this? I believe the issue is in the substring.