배열 크기에 대해 도움을 줄 수 있습니까? 역방향 배열은 한계를 벗어나지 않고 계속 수정하는 방법을 알 수 없습니다. 이 프로그램의 목적은 사용자가 문장을 입력하는 것입니다의 프로그램이 얼마나 많은 회문 존재하고, 그들이계속 경계 초과 오류 받기
package palindrome;
import java.util.*;
import javax.swing.*;
class Palindrome2
{
public static void main(String args[])
{
//String[] reverse; //Reverse word
String[] words;
int count = 0;
String palindromes[];
//User Input
String original = JOptionPane.showInputDialog("Words that are the same "
+ "forwards and backwards are called palindromes.\n"
+ "This program determines if a word is a palindrome.\n\n"
+ "Enter a word: ");
//Length of the Input
int length = original.length();
//Spliting the original into an Array
words = original.split("\\s");
//Reversing the User's Input
String[] reverse = new String[words.length];
for(int j = 0; j < words.length; j++){
int wordLength = words[j].length();
for (int i = wordLength - 1 ; i >= 0 ; i--) {
reverse[i] = reverse[i] + original.charAt(i);
}
}
//Determining if it is a Palindrome and Output
for (int l = 0; l < words.length; l++){
if (original.equalsIgnoreCase(reverse[l])) {
count = count + 1;
palindromes = new String[count];
palindromes[l] = reverse[l];
}
else {
}
}
JOptionPane.showMessageDialog(null, "There are " + count + " Palindromes"
+ " in this sentence");
JOptionPane.showMessageDialog(null, "The palindromes are:\n"+ palindromes);
}
}
* 정확한 오류 메시지 란 무엇입니까? 그리고 어떤 줄이 오류를 일으키는가? –