PROGRAM FOR PALINDROM STRING

This is the program palindrome string is a string which is equal to reverse of itself.

For example amma is a palindrome because reverse of amma is amma, by using the for loop we can find out string is palindrome or not.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.*;
public class PalindromStr
{
     public static void main(String[] args) throws IOException
     {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        int len,length;
        String  reverse ="";
        System.out.println("Enter First String:");
        String str = bf.readLine();
        len=str.length();
        System.out.println("length of the string is:"+len);  
          for ( int i = len - 1 ; i >= 0 ; i-- )
             reverse = reverse + str.charAt(i);
              if (str.equals(reverse))
                 System.out.println("Entered string is a palindrome.");
              else
                 System.out.println("Entered string is not a palindrome.");
    }
}

Output :palindrome string

gcdn