Palindrome.java
package com.techbyteslearn.lab.basic; public class Palindrome { public static void main(String[] args) { int number = 121; int temp = number; int finalNumber = 0; // Repeat the loop until the number becomes zero. while (number != 0) { // Get the last digit. int lastDigit = number % 10; // Build the reversed number. finalNumber = (finalNumber * 10) + lastDigit; // Remove the last digit from the number. number = number / 10; } // Compare the reversed number with the original number. 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. One important correction from the original comments: % 10 gets the last digit, not the first digit. Also, number has already become 0 by the time of the final comparison, so comparing with temp is the correct approach.
Happy Learning.
Nice post keep posting
ReplyDeleteangular certification
angularjs online training
MasterLabz
ReplyDeletePixmash
MazeEvents
Short Video App
Best Event Management Company in Chennai
Online Training Course Certification and Class
Hi,
ReplyDeleteThanks For Sharing Information.
sales tracking software free
Sales Tracking System
Sales Tracking Excel
Sales Tracking Software for Field Sales Teams
open source sales tracking software
Best Sales Tracking Software For Small Business
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!
ReplyDeleteGreat Information. Thanks for sharing.
ReplyDeleteJava classes in Pune
The insights shared throughout this article highlight why effective event planning requires both creativity and structure. Businesses searching for corporate event management in Chennai will find these points particularly relevant.
ReplyDelete