Welcome back to my blog! In this post, you will learn how to check whether a number is a palindrome or not in Java. A number is called palindrome if reads same when reversed. For example: 121, 111, 98789, etc. So let's get started! Algorithm: Enter the number which has to be checked. Assign the number to a temporary variable. Reverse the number. Compare the temporary number with the reversed number. If both are same, print a message "The number is palindrome!" Else print "The number is not palindrome." Given below is the code to check whether the number is palindrome or not: class Palindrome { public static void main(String[] args) { int rev, temp, sum = 0 ; int n = 121 ; // The number to be checked whether it is palindrome or not. temp = n; while (n > 0 ) { r = n% 10 ; // Getting the remainder sum = (sum * 10 ) + r; n = n/ 10 ;
Hello to all the technology lovers! If you love programming and tech stuff, you've come to the right place! I look forward to sharing accurate and more and more tech knowledge with you! If you like my post, kindly keep me motivated by sharing and subscribing to my Blog.