Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

returns the reverse of that String. Then write a second method that uses the fir

ID: 3551465 • Letter: R

Question

returns the reverse of that String. Then write a second

method that uses the first method to test whether or not an input

String is a palindrome. Your

method should return true if the String is a palindrome, and false

otherwise. In addition, write a main method that tests your method with a variety

of Strings that should return true and false values.

returns a String as a result. The method should print a

prompt to the screen asking the user to enter a palindrome.

It should then test the input. If it is not a palindrome, it

should print an error message and continue asking for a palindrome

until the user provides one. Once a palindrome has been

input, the method should return it. In addition, write a main

method that uses this method and displays the final palindrome to

the screen.



Explanation / Answer

Dear,


    public static void main(String[] args)
    {
        if(Palindrome("madam"))
           
        System.out.print("Pallindrome!");
        else
            System.out.print("Not Pallindrome!");
     }


    public static String ReverseString(String str)
    {
        String newStr = " ";
        //Loop to display string reverse
        for (int i= str.length()-1; i >= 0; i--)
        newStr += str.charAt(i);
        return newStr;
    }


    public static boolean Palindrome(String str)
    {
        if(str == ReverseString(str))
            return true;
        else
            return false;       
    }