60 495
Assignments Done
Successfully Done
In April 2018

Answer to Question #22294 in Java | JSP | JSF for MM

Question #22294
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
3.able was I ere I saw Elba
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."
Expert's answer
package Polindrom;

import java.util.Scanner;

public class main {

publicstatic void main(String[] args) {
char[]symb = new char[80];

Scannercs = new Scanner(System.in);

inti = 0;
while((ch = cs.nextLine().toCharArray()[0]) != 46)// reads from console
symb[i]= (char) ch;


publicstatic boolean isPalindrome(char[] a, int used) {
char[]tmp = new char[a.length];

intind = 0;
for(int i = 0; i < used - 1; i++) {
if(a[i] != 32) {
tmp[ind]= a[i];

intn = (ind) / 2;

Strings1 = "";
Strings2 = "";
for(int i = 0; i < n; i++) {

s1+= a[i];
s2+= a[used - 1 - i];
if(!s1.equalsIgnoreCase(s2)) {

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions