Palindrome in Java

Asked

Viewed 161 times

-2

Could someone help me with this exercise by explaining?

Ex: Write a Function that checks if a Given word is a palindrome. Character case should be Ignored. For example, isPalindrome("Deleveled") should Return true as Character case should be Ignored, Resulting in "deleveled", which is a palindrome Since it reads the same backward and foward.

public class Palindrome {
    public static boolean isPalindrome(String word) {
        throw new UnsupportedOperationException("Waiting to be implemented.");
    }

    public static void main(String[] args) {
        System.out.println(Palindrome.isPalindrome("Deleveled"));
    }
}
  • 1

    First, you should understand the definition of a palindrome. Then, think about how you will verify whether the word is a palindrome or not. If, after writing your code, you are still not getting it, put what you tried in your question.

  • I do not understand why have statement on the line of public Static

  • 2

    What statement?

1 answer

2


game-Xtreme, I will try to help you without giving the answer ready, after all it is an exercise and it is you who has to solve it, ok?

I see that you have difficulties in two things: logic and language.

Assuming you already know what a palindrome is (roughly speaking, the sequence of characters is the same in both directions, for example: 1234321).

First I suggest you design the solution, make like an algorithm, for example:

  • create a method that returns the word backwards (search the Stringutils API, or any other, or better yet, make your own to train...)

  • check that the received word is equal to the return of the method reversing the word.

  • return the result of the comparison

After you design the solution, go in parts, transcribing it to Java. As G. Otani P. said, when you try to do and have a specific question, then yes you ask a more targeted question.

Good luck.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.