---
description: Palindrome number in Java: A Palindrome number is a number that even when reversed is the same as the original number Examples of Palindrome Number 121, 393, 34043, 111, etc.
title: Palindrome Number Program in Java Using while &#038; for Loop
---

 

[Skip to content](#main) 

## What is Palindrome Number?

A **Palindrome number** is a number that remains the same number when it is reversed. For example, 131\. When its digits are reversed, it remains the same number. Palindrome number has reflection symmetry at the vertical axis. It refers to the word which has the same spelling when its letters are reversed.

**Examples of Palindrome Number in Java**

121, 393, 34043, 111, 555, 48084

**Examples of Palindrome Number**

 LOL, MADAM

## Palindrome Number Algorithm

Below is Palindrome number algorithm logic in Java:

* Fetch the input number that needs to be checked for being a [Palindrome](https://www.guru99.com/palindrome-program-in-python.html)
* Copy number into a temporary variable and reverse it.
* Compare the reversed and original number.
* If they are same, number is “palindrome number”
* Else number is not “palindrome number”

## How to check whether input number is Palindrome or not

Below is a Palindrome program in Java with [WHILE Loop](https://www.guru99.com/how-to-use-loops-in-javascript.html)

package com.guru99;
 
public class PalindromeNum {
 
	public static void main(String[] args)
	{
 
		int lastDigit,sum=0,a;    
		int inputNumber=171; //It is the number  to be checked for palindrome 
 
		a=inputNumber; 
        
        // Code to reverse a number
		while(a>0)
		{   System.out.println("Input Number "+a);  
			lastDigit=a%10; //getting remainder  
			System.out.println("Last Digit "+lastDigit); 
			System.out.println("Digit "+lastDigit+ " was added to sum "+(sum*10)); 
			sum=(sum*10)+lastDigit;  
			a=a/10;
			
		}    
 
		// if given number equal to sum than number is palindrome otherwise not palindrome
		if(sum==inputNumber)    
			System.out.println("Number is palindrome ");    
		else    
			System.out.println("Number is not palindrome");    
 
	}
 
}

### Code Output:

Input Number 171
Last Digit 1
Digit 1 was added to sum 0
Input Number 17
Last Digit 7
Digit 7 was added to sum 10
Input Number 1
Last Digit 1
Digit 1 was added to sum 170
Number is palindrome

## Program to Check Palindrome using for loop

Below is a Java program for Palindrome using for loop

package com.guru99;
 
public class PalindromeNum {
 
	public static void main(String[] args)
	{
 
		int lastDigit,sum=0,a;    
		int inputNumber=185; //It is the number  to be checked for palindrome 
 
		a=inputNumber; 
        
        // Code to reverse a number
	for( ;a != 0; a /= 10 )
		{   System.out.println("Input Number "+a);  
			lastDigit=a%10; //getting remainder  
			System.out.println("Last Digit "+lastDigit); 
			System.out.println("Digit "+lastDigit+ " was added to sum "+(sum*10)); 
			sum=(sum*10)+lastDigit;  
			a=a/10;
			
		}    
 
		// if given number equal to sum than number is palindrome otherwise not palindrome
		if(sum==inputNumber)    
			System.out.println("Number is palindrome ");    
		else    
			System.out.println("Number is not palindrome");    
 
	}
 
}

### Code Output:

Input Number 185
Last Digit 5
Digit 5 was added to sum 0
Input Number 1
Last Digit 1
Digit 1 was added to sum 50
Number is not palindrome

#### Summarize this post with:

ChatGPT Perplexity Grok Google AI 

**Stay Updated on AI** **Get Weekly AI Skills, Trends, Actionable Advice.** 

##### Sign up for the newsletter

Subscribe for Free 

You have successfully subscribed.  
Please check your inbox. 

![AI-Newsletter]() Chosen by over **350,000+** professionals 

[Scroll to top ](#wrapper)Scroll to top 

Toggle Menu Close 

Search for: 

Search

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://www.guru99.com/#organization","name":"Guru99","sameAs":["https://www.facebook.com/Guru99Official","https://twitter.com/guru99com"],"logo":{"@type":"ImageObject","@id":"https://www.guru99.com/#logo","url":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","contentUrl":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","caption":"Guru99","inLanguage":"en-US"}},{"@type":"WebSite","@id":"https://www.guru99.com/#website","url":"https://www.guru99.com","name":"Guru99","publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US"},{"@type":"BreadcrumbList","@id":"https://www.guru99.com/java-palindrome-program.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":"1","item":{"@id":"https://www.guru99.com","name":"Home"}},{"@type":"ListItem","position":"2","item":{"@id":"https://www.guru99.com/java-tutorials","name":"Java Tutorials"}},{"@type":"ListItem","position":"3","item":{"@id":"https://www.guru99.com/java-palindrome-program.html","name":"Palindrome Number Program in Java Using while &#038; for Loop"}}]},{"@type":"WebPage","@id":"https://www.guru99.com/java-palindrome-program.html#webpage","url":"https://www.guru99.com/java-palindrome-program.html","name":"Palindrome Number Program in Java Using while &#038; for Loop","dateModified":"2024-03-09T15:00:01+05:30","isPartOf":{"@id":"https://www.guru99.com/#website"},"inLanguage":"en-US","breadcrumb":{"@id":"https://www.guru99.com/java-palindrome-program.html#breadcrumb"}},{"@type":"Person","@id":"https://www.guru99.com/author/james","name":"James Hartman","description":"I am James Hartman, a seasoned professional in Oracle Certified Java Professional tutorials, specializing in crafting comprehensive guides to help you excel in your Java certification journey.","url":"https://www.guru99.com/author/james","image":{"@type":"ImageObject","@id":"https://www.guru99.com/images/james-hartman-author-v2-120x120.png","url":"https://www.guru99.com/images/james-hartman-author-v2-120x120.png","caption":"James Hartman","inLanguage":"en-US"},"worksFor":{"@id":"https://www.guru99.com/#organization"}},{"@type":"NewsArticle","headline":"Palindrome Number Program in Java Using while &#038; for Loop","keywords":"java","dateModified":"2024-03-09T15:00:01+05:30","articleSection":"Java Tutorials","author":{"@id":"https://www.guru99.com/author/james","name":"James Hartman"},"publisher":{"@id":"https://www.guru99.com/#organization"},"description":"Palindrome number in Java: A Palindrome number is a number that even when reversed is the same as the original number Examples of Palindrome Number 121, 393, 34043, 111, etc.","copyrightYear":"2024","copyrightHolder":{"@id":"https://www.guru99.com/#organization"},"name":"Palindrome Number Program in Java Using while &#038; for Loop","@id":"https://www.guru99.com/java-palindrome-program.html#richSnippet","isPartOf":{"@id":"https://www.guru99.com/java-palindrome-program.html#webpage"},"inLanguage":"en-US","mainEntityOfPage":{"@id":"https://www.guru99.com/java-palindrome-program.html#webpage"}}]}
```
