 Hello friends, I am Sanjay Gupta. In this video, I am going to demonstrate you how you can check whether the number is palindrome or not in Java. So first of all, I am going to import a package whose name is util. Inside this package, a class is predefined that is scanner. This class is required to read values from user. Then another class I am going to define that is palindrome. Inside this class, I am going to define main method definition. Inside this main method, I am going to implement the logic which will check whether the entered number is palindrome or not. So first of all, we have to know what is palindrome. Palindrome means if a numbers reverse is equal to the original number, then that number is set as palindrome. For example, if number is 123, then its reverse will be 321. So 123 is not a palindrome number. If number is 121, then its reverse will be 121. It means 121 is a palindrome number. So we have to check this scenario with the help of this program. So I am going to declare some variables. Now I am creating instance of scanner class. In this instance, I am passing system.in as constructor value, which is deciding that the input will be received from the console. Now through system.out.println, I am going to print a message, enter a number on output screen to receive the number from output screen or console. I am calling next int method. This next int method is defined in scanner class. So I hope you have understood why I have imported that class now. Now I am going to implement the logic. First I am going to implement the logic to convert this number into its reverse. Then after conversion, I will be checking it for palindrome. So I am implementing this while loop, which will find out reverse of num. So first time writing the statement temp equals to num modulus 10. It will provide remainder values. Then reverse equals to reverse into 10 plus 10. And then num equals to num by 10. So this loop will calculate reverse of num. After completion of this loop, I can compare num with reverse. So if both the values are equal, then I can print the message. Number is palindrome. If this condition is false, then number is not palindrome. So this way I have implemented the complete logic in front of you. But there is a minor change required when this loop will complete its execution. The value of num will become zero. And after completion of this loop at line number 17, if I compare num with reverse, so every time value of num will be zero. So I am going to take another variable as temp num. And before starting loop, I am storing value of num into temp num variable. And here in place of num, I am using temp num. So what will happen whenever this line number 11 will be executed, the original value which is available in num will be copied into temp num. So now temp num and num both have same values. After completion of this while loop, value of num will become zero. But temp num is containing the original value. So after completion of this loop, in place of num, I can use temp num for comparing the original value with the reverse value. So this way I have implemented the logic of checking whether the entered number is palindrome or not. I have saved this program in d drive in Java folder with name palindrome.java. Now I am going to open command prompt. I am moving to d drive and Java folder. Now I have to compile this code. So I am typing javac space palindrome.java. If errors it will show here, otherwise program will compile successfully. So in our case, program is compiled properly. It is not showing any error. Now I can execute this code with the help of Java space palindrome. Now it is asking for numbers. So first time entering 123. You can see it is showing number is not palindrome because reverse of 123 is 321 which is not equal to 123. Again I am executing this code. This time you can see I have entered 121. So it is showing number is palindrome. So in both the cases, both the cases program is printing correct results. I hope you have understood how we can check whether a number is palindrome or not in Java. If you want to watch more programming related videos, you can follow my YouTube channel. Thank you for watching this video.