Palindromic Number in Java

Published on 11 October 2020 (Updated: 11 October 2022)

Welcome to the Palindromic Number in Java page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

public class PalindromicNumber {

    public static void main(String[] args) {
        Long num;
        try {
            num = Long.parseLong(args[0]);
        } catch (Exception ignored) {
            num = null;
        }

        if (num == null || num < 0) {
            System.out.println("Usage: please input a non-negative integer");
        } else {
            System.out.println(isPalindromic(num));
        }
    }

    public static boolean isPalindromic(Long num) {
        char[] numChars = String.valueOf(num).toCharArray();
        for (int i = 0; i < numChars.length / 2; i++) {
            if (numChars[i] != numChars[numChars.length - 1 - i])
                return false;
        }
        return true;
    }
}

Palindromic Number in Java was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.