Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- public class MainClass {
- public static void main(String[] args) {
- int[] array = {1,2,3,4,5,4,3,2,1};
- System.out.println(Arrays.toString(array));
- System.out.println(_check(array));
- }
- private static boolean _check(int[] array) {
- boolean isPalindrome = true;
- int length = array.length;
- int firstIndex = 0;
- int lastIndex = array.length - 1;
- int formFirst = firstIndex;
- int fromLast = lastIndex;
- while (formFirst <= length / 2
- && fromLast >= length / 2) {
- System.out.print(array[formFirst] + " " + array[fromLast] + " // ");
- if(array[formFirst] != array[fromLast])
- isPalindrome = false;
- formFirst++;
- fromLast--;
- }
- return isPalindrome;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement