Java for loop check palindrome number

Question

We would like to check palindrome number for number with 5 digits.

A palindrome is a sequence of characters that reads the same backward as forward.

For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and 11611.

public class Main {
  public static void main(String[] args) {
    System.out.println(isPalindrome(12345));
    System.out.println(isPalindrome(12321));
  }/*from   w ww .  j a va  2  s .c  o m*/

  public static boolean isPalindrome(int value) {
    //your code here
  }
}


public class Main {
  public static void main(String[] args) {
    System.out.println(isPalindrome(12345));
    System.out.println(isPalindrome(12321));
  }

  public static boolean isPalindrome(int value) {
    int arrValue[] = new int[5];
    for (int i = 4; i >= 0; i--) {
      arrValue[i] = value % 10;
      value /= 10;
    }

    return ((arrValue[0] == arrValue[4]) && (arrValue[1] == arrValue[3]));
  }
}



PreviousNext

Related