Hello, I am making a program that tries to identify if an inputted word is a palindrome( word or number that reads backwards and forwards the same) but with the Pali() method of my program I have found out that when I compare the substring of letters it always ends up to be false and print out test2. I really don't see why if some one inputed "racecar" the r from the left and the r from the r from the right are any different. Anyways here is my code and I hope you guys can help me figure out what I did wrong or am not including. :)
/**
* Palinidrome
*
* @author
* @version 1/18/11
*/
import java.util.Scanner;
public class Palindrome
{
String[] letter;
int b=0;
boolean pal = true;
Palindrome(String w){
letter=new String[w.length()];
for(int a =0; a<w.length();a++){
letter[a] = w.substring(a,a+1);
}
}
public boolean Pali(){
System.out.println(letter[b] +"=="+ letter[b+letter.length-1]);
if(letter[b] == letter[b+letter.length-1]){
pal =true;
System.out.println("test1");
Pali();
}
else if (letter[b] != letter[b+letter.length-1]){
pal = false;
System.out.println("test2");
}
return pal;
}
public static void main(String[] args){
Scanner s = new Scanner(System.in);
System.out.println("Enter a word");
Palindrome p = new Palindrome(s.next());
boolean yay =p.Pali();
if(yay==true){
System.out.println("It is a palindrome");
}
else if(yay==false){
System.out.println("It is not a palindrome");
}
}
}