A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
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.
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.
No 'How to Implement the Solution' section available. Please consider contributing.
No 'How to Run the Solution' section available. Please consider contributing.