[Solved] How to check if a number is palindrome in Java? [closed]


public static boolean isPalindrome(int integer) {
    int palindrome = integer;
    int reverse = 0;

    // Compute the reverse
    while (palindrome != 0) {
        int remainder = palindrome % 10;
        reverse = reverse * 10 + remainder;
        palindrome = palindrome / 10;
    }

    // The integer is palindrome if integer and reverse are equal
    return integer == reverse; // Improved by Peter Lawrey

}

Advanced solution: (Provided by Shadov)

public static boolean isPalindrome(int integer) {
    String intStr = String.valueOf(integer); 
    return intStr.equals(new StringBuilder(intStr).reverse().toString());
}

Reference: http://www.java67.com/2012/09/palindrome-java-program-to-check-number.html#ixzz4emXfiD7V

Please do not just put up question without your work next time.

15

solved How to check if a number is palindrome in Java? [closed]