1
// Program to check a string is palindrome or or not

class Pal

{

static void pal(String k)

{
int flag=0;

int x;

char ch[]= k.toCharArray();

char p[]=k.toCharArray();

x=k.length()-1;

for(int i=0;i<k.length();x--,i++)

{

p[i]=ch[x];

}

System.out.println(p);

System.out.println(ch);

    if(p==ch)
    {
    System.out.println("palindrome String");
    }
    else
    {
    System.out.println("Not a palindrome string");
    }

}
public static void main(String... s)
{

String g="aba";

//String s1=g.toUpperCase();

System.out.println("input string is "+g);

pal(g);

}

}

/* Error:
output is :
input string is aba
aba
aba
Not a palindrome string
*/
cowls
  • 24,013
  • 8
  • 48
  • 78
  • This has been answered many many times on SO, look around for questions on double equals and Strings. It's the same problem here. – cowls Sep 17 '14 at 15:25
  • Also read this: http://www.java-examples.com/compare-two-java-char-arrays-example – cowls Sep 17 '14 at 15:28
  • I believe you're lazy enough to google, so here is the answer: double equals operator will return true on objects if and only if when the two references point to the exact same object on heap. – ares Sep 17 '14 at 15:35
  • Double equals compares two *values* to see if they are equal. – Hot Licks Sep 17 '14 at 16:08

0 Answers0