你好,我试图做一个程序,检查一个单词的第一个字母,看它是否等于最后一个字母。我的java编译正常,但什么都没显示
public class isPalindrome
{
public static void main(String[] args)
{
// Create an array of strings to test.
String[] testStrings = { "Able was I ere I saw Elba",
"Rats live on no evil star",
"Four score and seven years ago",
"Barrack Obama",
"Now is the time for all good men",
"Desserts I stressed",
"Ask not what your country can do for you",
"Kayak",
"Vegeta",
"A Man, A Plan, a canal, Panama!"};
for (int i = 0; i < testStrings.length; i++)
{
System.out.print("\"" + testStrings[i] + "\"");
if (Palindrome(stripString(testStrings[i])))
System.out.println(" is a palindrome.");
else
System.out.println(" is not a palindrome.");
}
}
public static String stripString(String strip)
{
strip = strip.toUpperCase();
String stripped= "";
for (int i= 0; i< strip.length(); i++)
{
if (Character.isLetter(strip.charAt(i)))
stripped += strip.charAt(i);
}
return stripped;
}
public static boolean Palindrome(String str)
{
boolean status = false;
if (str.length() <= 1)
status = true;
else if (str.charAt(0) == str.charAt(str.length()-1))//Recursive Case
{
status = Palindrome (str.substring (1, str.length()-1));
}
return status;
}
}
真的什么都没有?至少从for循环的东西应该打印... – BoltClock 2011-03-02 08:05:04
这看起来很好,我的程序终止?还是它在某个地方陷入了无限循环? – Argote 2011-03-02 08:06:56
这就是我在想什么? – lonesarah 2011-03-02 08:07:06