This code is printing wrong answer
Scanner scn=new Scanner(System.in);
String stri=scn.nextLine();
StringBuilder str=new StringBuilder(stri);
StringBuilder rev=new StringBuilder();
for(int i=str.length()-1;i>=0;i–)
rev.append(str.charAt(i));
if(rev.equals(str))
System.out.println(“true”);
else
System.out.println(“false”);
String_is_palindrome
Hi @Cheshtha,Instead of making stringbuilders make Strings here one as str which you will make equal to stri and other as rev and initially make rev as an empty string then at the place of rev.append do rev=rev+str.chaAt(i).
Hi @Cheshtha ,
As you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.
Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.
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.