//Palindrone from a String
public class Palindrome {
static int track = 0;
public static void main(String args[]){
String str = "abcicbbcdefggfed ";
char[] charArray = str.toCharArray();
Palindrome p1 = new Palindrome();
p1.find_palindrome(charArray);
}
void find_palindrome(char[] ch){
for(int i=0; i< ch.length; i++){
if(ch[i] == ch[i+1]){
checkPalindrome(ch, i, i+1);
}
else{
checkPalindrome(ch,i-1,i+1);
}
}
}
void checkPalindrome(char[] c, int left, int right){
int count=0,l=0,r=0;
while(left >= 0 && right <= c.length){
while(c[left] == c[right]){
left--;
right++;
count = count + 1;
}
break;
}
if(count > track){
track = count;
l = left;
r = right;
}
if(count>1){
for (int j=left+1;j<=right-1;j++){
System.out.println(c[j]);
}
System.out.println("--");
}
}
}
特定の例外エラーが表示されますが、解決方法がわかりません。私はその初心者の質問を知っているので、あなたの答えと一緒に説明が本当に役に立ちます.
編集:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 17
at Palindrome.find_palindrome(Palindrome.java:14)
at Palindrome.main(Palindrome.java:8)