0

import java.util.*;

public class palindrome

{ // class open

public static void main(String args[])

{ //main open

    Scanner sc = new Scanner(System.in);

    System.out.println("Enter the String");

    String str = sc.nextLine();

    String reverse="";

    int length= str.length();

      for (int i = length - 1; i >= 0; i--)

      {

         char ch=str.charAt(i);
         reverse = reverse+ch;
      }
      if (reverse == str)
         System.out.println(str+" is a palindrome.");  
      else  
         System.out.println(str+" isn't a palindrome.");  
} //main close

} //class close

It's always giving the "ins't a palindrome" output

Adrian
  • 1
  • The `==` operator checks if two references are exactly the same, which is not what you want to test. The `.equals(...)` method of String will test if the two Strings have the chars in the same order, which *is* what you want to test. – Hovercraft Full Of Eels May 14 '22 at 12:27

0 Answers0