因此,这段代码应该输入一个字符串,向后转动该字符串,然后比较原始字符串和后向字符串,看它们是否匹配,如果它们是回文,则返回true。在向后转动文本之前,我正在尝试将其转换为小写,但是我在获取传递给方法的参数,将其转换为小写并将其存储在行中时,会出现“无法找到符号”错误一个新的变量。
我不知道是什么导致了这一点,从我所知道的java(这并不多),在方法中定义变量时“无法找到符号”错误通常是在方法或类无法访问任何内容时引起的value被分配给新变量,但在我看来,方法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;
}
}
答案 0 :(得分:1)
您正试图调用一个函数
这需要括号()
。