0
public class Tree {
    public String stringrev(String str) {
        if (str.equals(""))
            return "";
    
        return stringrev(str.substring(1)) + str.charAt(0);
    }
    
    public static void main(String args[]) {
        String x =  "racecar";
        Tree t = new Tree();
        String y = t.stringrev(x);
        System.out.println(y);

        System.out.println(x == y ? "Yes Palindrome" : "Not a palindrome");
    }
}

why the output is saying not a palindrome when both the strings match equally? output is wrong "not a palindrome" why? when both the strings are equal after reversing

0009laH
  • 1,735
  • 11
  • 24
John
  • 1
  • 1

0 Answers0