Write a program in java to find out given string is palindrome or not?

import java.util.Scanner;

class Palindrome

{

                public static void main(String arg[])

                {

                                Scanner in=new Scanner(System.in);

                                System.out.print("Enter Word - ");

                                String s=in.next();

                                char c[]=s.toCharArray();

                                int j=s.length()-1;

                                int i=0;

                                for(i=0;i<s.length();i++)

                                {

                                                if(c[i]!=c[j])

                                                                break;

                                                j--;

                                }

                                if(i<s.length())

                                                System.out.println("Not Palindrome");

                                else

                                                System.out.println("Polindrone");

                }

}

Find out given string is palindrome or not.PNG

, , , , , , ,

Leave a Reply