Blog

Palindrom of string in java

By Satyapriya Nayak Blogs | Java Sep 22, 2011
In this blog we will know whether a given string is palindrom or not.

In this blog 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


Ex: Provide a string to test :- BOB

Output:- String is palindrom

COMMENT USING

PREMIUM SPONSORS

Hire Mobile & Web Developer on demand. 100% satisfaction. Try for 1 week or Money Back. Local and remote developers available all over USA.

Latest Blogs