+ 2
Java Palindrome Problem
It's an assignment I'm working on, I have to modify the code to eliminate the runtime error! It's prints true only if the palindrome has an odd length, false if it's no palindrome but error if it's a palindrome but has an even length. I tried changing the "i != j" in the while loop to "i <= j" and it stops the error but prints false for even length palindrome. Original code below 👇 https://code.sololearn.com/cLQ1Dlzp9WMn/?ref=app
7 odpowiedzi
+ 2
Use condition i <= j
And return i > j;
let's see it works.
+ 3
Yes. That's why I gave hints so you can rethink..
You're welcome..
+ 1
It not enough details to find mistakes..
Can you show your code by saving in playground..?
edited:
+ 1
Jayakrishna🇮🇳 I already linked the code!
+ 1
For odd length ex:
aba
i != j becomes false and returns i==j true
But for even length,
Ex: abba, at end i=2 , j=1 when loop exits so return i==j returns false.
you need to think about logic again.
+ 1
I know about that, I don't know what to do that's why I came here
+ 1
It's working Thanks! Soo close 😅