I have been able to output a palindrome but now it does so even if it is not a palindrome. Thanks you in advance for any help. ;)
import java.util.*;
public class ec2
{
static Scanner kb = new Scanner(System.in);
public static void main(String[] args)
{
String word = " ";
String s = " ";
char letter;
int i=0, j=0;
boolean isPal;
System.out.print("Enter a palindrome (CTRL-D to end): ");
while (kb.hasNext() )
{
s =kb.nextLine();
for (i=0; i < s.length(); i++) {
letter = s.charAt(i);
if(Character.isLetter(letter))
{
word += letter;
}
}
if(isPal(word))
System.out.println(word + " is a Palindrome");
else
System.out.println(word + " is not a Palindrome");
word = "";
System.out.println("Enter a palindrome (CTRL-D to end): ");
}
}
public static boolean isPal(String s)
{
int len = s.length();
int i, j;
char ch1, ch;
j = len - 1;
boolean found = false;
for (i = 0; i < len; i++)
{
ch = s.charAt(i);
ch1 = s.charAt(j);
if(!Character.isLetter(ch) && !Character.isLetter(ch1) && ch != ch1)
{
found = false;
}
else
{
found = true;
}
j--;
}
return found;
}
}