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

In java please, A palindrome is a word or phrase that is the same backwards as i

ID: 3699365 • Letter: I

Question

In java please,

A palindrome is a word or phrase that is the same backwards as it is forwards. For example, "A palindromes. Note that we ignore spaces and case differences in a phrase when determining whether or not it is a palindrome. Toyota", "Able was I ere I saw Elba", "Step on no pets" or "Never odd or even" are all Write a program called Palindrome that does the following: 1. Read in an entire line from the keyboard as a String 2. Remove the spaces 3. Reverse the string 4. Compare the resulting reversed string to the version with its spaces removed in order to determine if the phrase is a palindrome. 5. Print out that the phrase is or is NOT a palindrome. Example 1: Please enter a sentence: Able was I ere I saw Elba The sentence is a palindrome! Example 2: Please enter a sentence: Mary had a little 1amb The sentence is No?a palindrome Example 3: Please enter a sentence: A Toyota The sentence is a palindrome!

Explanation / Answer

import java.util.Scanner;

class ChkPalindrome

{

public static void main(String args[])

{

String str, rev = "";

Scanner sc = new Scanner(System.in);

System.out.println("Enter a string:");

str = sc.nextLine();

int length = str.length();

for ( int i = length - 1; i >= 0; i-- )

{

rev = rev + str.charAt(i);

}

if (str.equals(rev))

{

System.out.println(str+" is a palindrome");

}

else

{

System.out.println(str+" is not a palindrome");

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote