.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Javascript >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

To know whether a given string is palindrom or not in java

Posted By:satyapriyanayak       Posted Date: July 07, 2014    Points: 40    Category: Javascript    URL: http://www.dotnetspark.com  

In this Code Snippets we will know whether a given string is palindrom or not.
 

A palindrome is a word, phrase, number that can be read the same way in either direction.


import java.util.*;
public class palindrom
{
  public static void main(String arg[])
{
    System.out.println("Provide a string to test");
    Scanner sc=new Scanner(System.in);
    String str1=sc.next();
    String str2="";
     for(int i=str1.length()-1;i>=0;i--)
       str2=str2+str1.charAt(i);
    
  if(str1.equals(str2))
    System.out.println("Palindrom");
   else
    System.out.println("Not a palindrom");
 }
}

Compile:-

javac palindrom.java
java palindrom

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend