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

A palindrome is a word or phrase that reads the same forward and backward, ignor

ID: 3625699 • Letter: A

Question

A palindrome is a word or phrase that reads the same forward and backward, ignoring blanks and considering uppercase and lowercase versions of the same letter to be equal.for example,the following are palindromes:
1.warts n straw
2.radar
3.able was I ere I saw Elba
4.xyzczyx
Write a program that will accept a sequence of characters terminated by a period and will dedide whether the string--without the period---is a palindrome.You may assume that the input contains only letters and blanks and is at most 80 characters long.Include a looop that allows the user to check additional strins until she or he requests that the program ind. Hint Define a static method called isPalindrome
that begins as follows:
/**
Precondition: The array a contains letters and blanks in positions a[0] through a[used - 1]. Returns true if the string is a palindrome and false otherwise.
*/
public static boolean isPalindrome(char[] a, int used)

Your program shoud read the input characters int an arra y whose base type is char and then call the preceding method.the int variable used keeps track of how nuch of the array is used, as described in the section entitled "Partially Filled Arrays."

Explanation / Answer

Dear User, import java.util.Scanner;
import java.io.*;         class Palindrome
{
public static void main(String [] args)
{
   String in;
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter string: ");
in = keyboard.nextLine();
int size=in.length();
if( ispalindrome(in,0,size-1))
System.out.println("Pallindrome");
else
System.out.println("Not Pallindrome");
System.exit(0);
}
public static boolean ispalindrome(String str, int i, int j)
{
if (i >= j)
{
return true;
}
  if (str.charAt(i) == str.charAt(j))
{
return ispalindrome(str, i + 1, j - 1);
}
return false;
}
} I hope this will helps to You! I hope this will helps to You!
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