-8
public boolean isPalindrome(String s){
   for(int i = 0;i< s.length();i++ ) {
       if(s.charAt(i)==s.reverse)
   }
}

How to complete this to accomplish this goal?

Roddy of the Frozen Peas
  • 14,380
  • 9
  • 49
  • 99

1 Answers1

0

I think what you're trying to do is this?

public boolean isPalindrome(String s) {
    for (int i = 0; i < s.length() / 2; i++) {
        if (s.charAt(i) != s.charAt(s.length() - i - 1)) {
            return false;
        }
    }
    return true;
}

You can reverse strings using StringBuilder, so this could be more easy written as

public boolean isPalindrome(String s) {
    return new StringBuilder(s).reverse().toString().equals(s);
}
Adam
  • 35,919
  • 9
  • 100
  • 137