A palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward. This example show how you are going to check a given array is a palindrome or not.

public class CheckPalindrome {
    public static String[] array = new String[5];

    public static void main(String[] args) {
        boolean isPalindrome = true;
        array = new String[]{"A", "B", "C", "B", "A"};
        for (int i = 0 ; i < array.length ;i ++)    {
            if( array[i] != array[array.length - 1 - i] ) {
                isPalindrome = false;
            }
        }
        if( isPalindrome ) {
            System.out.println("Array is paradigm");
        } else{
            System.out.println("Array is not a paradigm");
        }

    }
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *

WP Facebook Auto Publish Powered By : XYZScripts.com