The program is intended to read a file with a few lines of strings to determine whether or not they are palindromes. I'm getting an error while compiling - tagged where the error shows up. I'm not sure whether or not it is going to read the lines correctly from the file or not either since I can't compile it.
import java.io.*;
public class Palindromes
{
public static BufferedReader inFile;
public static void main (String[]args)throws IOException
{
inFile = new BufferedReader(new FileReader("palindrome.dat"));
System.out.println("Enter a word or phrase: ");
String s = inFile.readLine();
s = s.toLowerCase();
String toTest = s;
int index;
for(int index = 0;index < s.length();index++)
{
if(Character.isLetterOrDigit(s.charAt(index))
cleanStr += s.charAt(index); [COLOR="Red"]//error shows up here - it is looking for a "{" ?[/COLOR]
}
if(isPalindrome(toTest))
System.out.println(s + " IS A PALINDROME");
else
System.out.println(s + " IS NOT A PALINDROME");
}
public static boolean isPalindrome(String s)
{
if (s.length() <= 1)
return true; // Base case
else
{
if (s.charAt(0) == s.charAt(s.length() - 1))
return isPalindrome(s.substring(1, s.length() - 1 ) );
else
return false;
}
}