Forum Stats

  • 3,783,234 Users
  • 2,254,746 Discussions
  • 7,880,334 Comments

Discussions

Write a function to that accept the string through keyboard to check the string is Palindrome.

User_F1EJL
User_F1EJL Member Posts: 1 Green Ribbon

Write a function to that accept the string through keyboard to check the string is Palindrome.

Answers

  • User_GUX87
    User_GUX87 Member Posts: 1 Green Ribbon
    import java.util.Scanner;
     
    class ChkPalindrome
    {
       public static void main(String args[])
       {
          String str, rev = "";
          Scanner sc = new Scanner(System.in);
     
          System.out.println("Enter a string:");
          str = sc.nextLine();
     
          int length = str.length();
     
          for ( int i = length - 1; i >= 0; i-- )
             rev = rev + str.charAt(i);
     
          if (str.equals(rev))
             System.out.println(str+" is a palindrome");
          else
             System.out.println(str+" is not a palindrome");
     
       }
    }