public class palindrome{
public static void main(String[] args){
String str1 = "eye",str2 = "bye";
System.out.println("palindrome detection");
System.out.println(str1 + " "+ ispalindrome(str1));
System.out.println(str2 + " "+ispalindrome(str2));
}
static boolean ispalindrome(String s){
int left =0;
int right = s.length() -1;
while(left<right){
if (s.CharAt(left) != s.CharAt(right))
return false;
left++;
right--;
}
return true;
}
}
错误是:cannot resolve symbol就是s.CharAt(left) != s.CharAt(right))这行出问题。谢谢
public static void main(String[] args){
String str1 = "eye",str2 = "bye";
System.out.println("palindrome detection");
System.out.println(str1 + " "+ ispalindrome(str1));
System.out.println(str2 + " "+ispalindrome(str2));
}
static boolean ispalindrome(String s){
int left =0;
int right = s.length() -1;
while(left<right){
if (s.CharAt(left) != s.CharAt(right))
return false;
left++;
right--;
}
return true;
}
}
错误是:cannot resolve symbol就是s.CharAt(left) != s.CharAt(right))这行出问题。谢谢
按规范,方法名都是小写开头的
public char charAt(int index)
Returns the char value at the specified index. An index ranges from 0 to length() - 1. The first char value of the sequence is at index 0, the next at index 1, and so on, as for array indexing.
If the char value specified by the index is a surrogate, the surrogate value is returned.
Specified by:
charAt in interface CharSequence
Parameters:
index - the index of the char value.
Returns:
the char value at the specified index of this string. The first char value is at index 0.
Throws:
IndexOutOfBoundsException - if the index argument is negative or not less than the length of this string.
很有帮助的
注意大小写
java是区别大小写的