所以这段代码应该输入一个字符串,将该字符串向后翻,然后比较原始字符串和反向字符串以查看它们是否匹配,如果它们是回文,则返回true。在向后翻文本之前,我试图将它转换为小写,但是我在传递给方法的参数行上出现“无法找到符号”错误,将其转换为小写,并将其存储在一个新的变量。“找不到符号错误”,定义了一个字符串
我不知道是什么导致了这一点,从我所知道的java(这并不多),“找不到符号”错误,而定义方法内的变量往往是当方法或类无法访问无论赋值给新变量,但在我看来,像isPal应该没有问题的变量'str'。请有人能告诉我我要去哪里吗?
public class Lab14TEXT05st
{
public static void main (String args[])
{
System.out.println("\nLab14TEST05\n");
boolean finished = false;
do
{
System.out.print("Enter a string ===>> ");
String str = Expo.enterString();
System.out.println();
System.out.println("Entered String: " + str);
System.out.println("Palindrome: " + Palindrome.isPal(str)); <---This line should be passing string str to 's' in the isPal method
System.out.println("Almost Palindrome: " + Palindrome.almostPal(str)); // used only for the 100 and 110 point versions
System.out.println("Least Palindrome: " + Palindrome.leastPal(str)); // used only for the 110 point versions
System.out.println();
System.out.print("Do you wish to repeat this program [Y/N]? ===>> ");
char repeat = Expo.enterChar();
finished = (repeat != 'Y' && repeat != 'y');
System.out.println();
}
while (!finished);
}
}
class Palindrome
{
public static boolean isPal(String s)
/*
* Precondition: s is an arbitrary String.
* Postcondition: The value of true is returned if s is a Palindrome, false otherwise.
*/
{
String s2 = s.toLowerCase; <--The error message points to this line
String s3 = "";
int n = s.length() - 1;
for (int k = n; k >= 0; k--){
s3 += s2.charAt(k);
}
if (s2.equals(s3)){
return true;
}
}
我想你的作业会更有价值,如果你自己做... – Tchoupi 2012-03-26 04:21:27
谁把地狱标记为C#? – leppie 2012-03-26 05:44:55