Java palindrome exercise


Hello everyone,

the following code is a palindrome exercise I am working out in eclipse. the exercise is to return whether the given user input is a palindrome or not. Can anyone help with this?

public class Palindrome {
public static void main(String args) {
try {
} catch (Exception e) {
System.out.println(“Can’t input empty string!”);
public static boolean isPalindrome() throws Exception{
Scanner input = new Scanner(;
System.out.println(“Type in a phrase and press Enter to see if the word is a Palindrome…”);
String phrase = input.nextLine();
int length = phrase.length();
int c = 0;

            while (c <= length/2) {
                System.out.println(length - 1 - c);
                if (input.charAt(c) != input.charAt(length - 1 - c)) {
                    return false;
            return true;

With this code, eclipse is giving me an error towards the bottom in my ‘if’ statement. The error is - the method charAt(int) is undefined for the type Scanner.

Thank you!


I found this, which may give a hint…