Palindrome error | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Palindrome error

I have written logic for palindrome, by splitting the word in char array and comparing them. But the if condition is failing again and again Refer line no 70 input : string type https://code.sololearn.com/cw9Fl0731H0x/?ref=app

14th Jun 2020, 2:13 PM
Shariff
Shariff - avatar
5 Answers
+ 5
To convert in char array do this. Then it will work fine. char []s=word.toCharArray();
14th Jun 2020, 2:29 PM
A͢J
A͢J - avatar
+ 3
Store the character array in reverse order in a string variable and compare it with input using the equals method.
14th Jun 2020, 2:31 PM
Avinesh
Avinesh - avatar
+ 3
Thankyou zemiak ,AJ Anant and Avinesh All the 3 answers me. The most beautiful thing of sololearn is that u get multiple type of correct answers It will help us understand many things very quickly Thanks.
14th Jun 2020, 2:37 PM
Shariff
Shariff - avatar
+ 2
Shariff We can solve any problem in many ways. And I think we are at Good plateform. Different people gives different and correct answer. We can learn so many things here.
14th Jun 2020, 2:44 PM
A͢J
A͢J - avatar
+ 1
if (! s[i].equals(s[s.length-1-i]) ){
14th Jun 2020, 2:29 PM
zemiak