Slip No 25 Q A

Q. Write a java program to check whether given string is palindrome or not.[15 M]

import java.util.Scanner;

class PalindromeString
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter a string: ");
        String str = sc.nextLine();

        String rev = "";

        // Reverse string
        for(int i = str.length() - 1; i >= 0; i--)
        {
            rev += str.charAt(i);
        }

        // Check palindrome
        if(str.equalsIgnoreCase(rev))
            System.out.println("String is Palindrome");
        else
            System.out.println("String is Not Palindrome");
    }
}
Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top