Program Statement: Write a JAVA program to check given string is palindrome or not.


Tested on:

Software: Windows 8, Jdk 1.6,   Netbeans IDE

Hardware: Intel Core i3, 4 GB RAM, 500 GB HDD




Source Code

@Author: Praveen Kanwar
import java.util.*;
public class StringPalindrome {
    public static void main(String[] args)
    {
        Scanner sn=new Scanner(System.in);
        System.out.println("Enter any string: ");
        String str=sn.next();
        StringBuffer sb = new StringBuffer(str);
            sb.reverse();
   
        if(str.equals(sb.toString()))
            System.out.println("The given string "+str+" is a palindrome");
        else
            System.out.println("The given string "+str+" is not a palindrome");


    }
}

Output

 Enter any string:
madam
The given string madam is a palindrome

 Enter any string:
cat
The given string cat is not a palindrome
Next
This is the most recent post.
Previous
Older Post

Post a Comment

 
Top