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

Solve this problem: A palindrome is a string of characters that reads the same f

ID: 3541357 • Letter: S

Question

Solve this problem:
A palindrome is a string of characters that reads the same forward and backward. Write a program that reads in strings of characters and determines if each string is a palindrome. Each string appears on a separate input line. Echo-print each string, followed by "Is a palindrome" if the string is a palindrome or "Is not a palindrome" if the string is not a palindrome. For example, given the input string
Able was I, ere I saw Elba.
The program should print "Is a palindrome." In determining whether a string is a palindrome, consider uppercase and lowercase letters to be the same and ignore punctuation characters and spaces.
Notes on this problem:
the input file that you will be reading palindromes from is called

Explanation / Answer

please rate - thanks


tested with JGrasp

any questions/problems --ask


import java.io.*;
public class palindrome
{
public static void main(String args[]) throws IOException
{BufferedReader in=new BufferedReader(new FileReader("pals.txt"));

PrintStream out=new PrintStream(new File("palsout.txt"));

boolean palin;
String input,reveresed;
input=in.readLine();
while(input!=null)
{
if(isPalindrome(input))
   out.println(input+" is a Palindrome");
else
    out.println(input+" is not a Palindrome");
input=in.readLine();

}
}
public static boolean isPalindrome(String input )
{int i=0,j;
boolean y=false;
input=filter(input);
j=input.length()-1;
while(input.charAt(i)==input.charAt(j)&&i<=j)
      {i++;
       j--;
       }
if(i>j)
    y=true;
return y;
}
public static String filter(String input)
{String str="";
int i;
for(i=0;i<input.length();i++)
   if(Character.isLetter(input.charAt(i)))
        str=str+Character.toLowerCase(input.charAt(i));
return str;
}
}