Tuesday, 3 January 2017

Write a Java Program to check String is Palindrome or not ?

Palindrome means the string remain same when reversed. for Example "malayalam"
is palindrome as reverse of "malayalam" is same, whereas "pushkar" is not palindrome as reverse of "pushkar" is "rakhsup". 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
public class Palindrome {

 public static void isPalindrome(String str){
  String reverse = "";
  for(int i=str.length()-1;i>=0;i--){
   reverse+= str.charAt(i);
  }
  if(str.equals(reverse)){
   System.out.println(str+" is Palindrome");
  }
  else{
   System.out.println(str+" is Not Palindrome");
  }
 }
 public static void main(String[] args) {
  Palindrome.isPalindrome("malayalam");
  Palindrome.isPalindrome("pushkar");
 }
}

Output :

malayalam is Palindrome
pushkar is Not Palindrome

      
Blog Author - Pushkar Khosla,
Software Developer by Profession with 3.0 Yrs of Experience , through this blog i'am sharing my industrial Java Knowledge to entire world. For any question or query any one can comment below or mail me at pushkar.itsitm52@gmail.com.

This blog is all about to learn Core Java ,Interview Programs and Coding tricks to polish your Java Knowledge. If you like the content of this blog please share this with your friends.



Share this Blog with yours Friends !!

No comments:

Post a Comment