Ispalindrome or not

import java.util.*;
public class Main {
public static boolean isPalindrome(String str)
{
int i=0,j=str.length()-1;
while(i<j)
{
if(str.charAt(i)!=str.charAt(j))
return false;
i++;
j–;
}
return true;
}
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
String str=sc.next();
if(isPalindrome(str))
System.out.print(“true”);
else
System.out.print(“no”);
}
}

out of 4 testcases 2 went wrong can u plz correct where i done mistake

@karthik1989photos lemme check buddy

@karthik1989photos bro a small mistake, you have to print false not no.

@A17CRX0016,
Take as input N, a number. Take N more inputs and store that in an array. Write a recursive function which tests if the array is a palindrome and returns a Boolean value.

Now you are taking input as strings which stores only the first number. Hence you will always get answer as true.

Also, try implementing a recursive solution instead of a iterative solution as mentioned in the question.

And print “false” instead of “no”.

Input:
5
3
2
1
2
4

Your answer:
true
Correct answer:
false

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.