13 July, 2019

Find the number is palindrome or not


In this article, we will see how to check if a number is palindrome or not. This is a very basic questions in interview. But, you never know about what kind of question the interviewer will ask. So, better you prepare for every certain questions. Also there is a question to find all palindrome number from a list.  Find few more collection interview question.  Today we will see how to check a number is palindrome or not. 


Palindrom.java


package com.javadevelopersguide.lab.basic;
/**
 * This program illustrates how to check a number is palindrome or not.
 *
 * @author manoj.bardhan
 *
 */
public class Palindrom {
public static void main(String[] args) {
int number = 121;
int temp = number;
int finalNumber = 0;
// Repeat the loop until the number became zero.
while (number != 0) {
// Get the First Digit (i.e. 1)
int firstDigit = number % 10;
// Get the Result number.
finalNumber = (finalNumber * 10) + firstDigit;
// Now get the remaining digits , after finding the first digit
number = number / 10;
}
// Now compare the finalNumber and number both are same or not.
if (finalNumber == temp) {
System.out.println("This number is a Palindrome.");
} else {
System.out.println("This number is not a Palindrome.");
}
}
}


Output -

This number is a Palindrome.

10 comments:

  1. Nice article! It is very inspiring to me and I am regularly read your new posts I have gone through your post and i found it very helpful if any one who want to learn java core to advance Get a free demo call on 9311002620 https://www.htsindia.com/Courses/JAVA/core-java-training-course-institute

    ReplyDelete
  2. This blog is so cool. I am Java training course online. This blogs helps me find out better understanding about salesforce training. Thank you for this blog!

    ReplyDelete
  3. Struggling with your academic assignment? Struggling with programming Assignment ? No worries! sampleassignment.com is finally here for you. With us, you'll get the best support for your academic problems. We've got a team of experts ready to provide you with the best Programming Assignment help. All you have to do is ask and our experts will provide it right away! Along with that, we also offer huge offers and discounts in online assignment

    ReplyDelete
  4. Thanks for this blog, Keep sharing your thoughts like this...
    Struts Course in Chennai
    Hibernate Course in Chennai

    ReplyDelete

  5. I am really very happy to visit your blog. Directly I am found which I truly need. please visit our website for more information
    Data visualization Service in USA

    ReplyDelete
  6. Awesome Article Thanks for sharing your valuable information Hire Full stack developer from Technoduce for your custom Full satck development project

    ReplyDelete