所以我正在用java做一个回文检查器,我似乎遇到了障碍,这是我的代码到目前为止:
public class StringUtil
{
public static void main(String[] args)
{
System.out.println("Welcome to String Util.");
Scanner word = new Scanner(System.in);
String X = word.nextLine();
String R = palindrome(X);
System.out.println();
System.out.println("Original Word: " + X);
System.out.println("Palindrome: " + R);
}
public static boolean palindrome(String word)
{
int t = word.length(); //length of the word as a number
int r = 0;
if(word.charAt(t) == word.charAt(r))
{
return true;
}
else
return false;
}
到目前为止,我只希望它检查第一个字母是否与最后一个字母相同,但是当我编译它时,我在“String R = palindrome(X);”上得到一个不兼容的类型错误。我如何让它在它下面的输出语句上打印真或假?