Palindrom of string in java

Introduction 

 
In this blog, we will know whether a given string is palindrome or not.
 
A palindrome is a word, phrase, number that can be read the same way in either direction.
  1. import java.util.*;  
  2. public class palindrom   
  3. {  
  4.  public static void main(String arg[])   
  5.  {  
  6.   System.out.println("Provide a string to test");  
  7.   Scanner sc = new Scanner(System.in);  
  8.   String str1 = sc.next();  
  9.   String str2 = "";  
  10.   for (int i = str1.length() - 1; i >= 0; i--)  
  11.    str2 = str2 + str1.charAt(i);  
  12.   if (str1.equals(str2))  
  13.    System.out.println("Palindrom");  
  14.   else  
  15.    System.out.println("Not a palindrom");  
  16.  }  
  17. }   
Compile:-
 
javac palindrom.java
java palindrome
 
Ex: Provide a string to test:- BOB
Output:- String is palindrome