I have a method to test if a number is palendromic (the function is
public boolean isPalen(int n))
It always returns false. Even if I change main to pass in a palendromic number directly.
Why? Can someone give me some tips?
Code:
public class Main {
public static void main(String args[]){
System.out.println("Starting....");
Thread t1 = new Thread(){
public void run(){
new Main().loop(10,99);
}
};
t1.start();
System.out.println("Done!");
}
public void loop(int l, int h){
for(int ih = l; ih <= h; ih++){
for(int il = 10; il < 100; il++){
if(isPalen(ih * il))
System.out.println("\t" + ih * il);
}
}
}
public boolean isPalen(int n){
String s1 = Integer.toString(n);
String s2 = reverse(s1);
return (s1 == s2);
}
public String reverse(String s) {
return new StringBuffer(s).reverse().toString();
}
}