📘 Lesson  ·  Lesson 48

Palindrome Number

Palindrome Number Program in Java

A number is a palindrome if it reads the same reversed, like 121 or 1331.

Java Program

int num = 121, rev = 0, temp = num;
while (temp != 0) {
    rev = rev * 10 + temp % 10;
    temp /= 10;
}
if (num == rev) System.out.println(num + " is Palindrome");
else System.out.println(num + " is Not Palindrome");

Output

121 is Palindrome

How it Works

  • We reverse the number digit by digit using % and /.
  • If the reversed number equals the original, it is a palindrome.

Summary

  • A number is a palindrome if it reads the same reversed, like 121 or 1331.

Palindrome Number Program in Java

एक संख्या palindrome है अगर उलटी पढ़ने पर भी वैसी ही हो, जैसे 121 या 1331।

Java Program

int num = 121, rev = 0, temp = num;
while (temp != 0) {
    rev = rev * 10 + temp % 10;
    temp /= 10;
}
if (num == rev) System.out.println(num + " is Palindrome");
else System.out.println(num + " is Not Palindrome");

Output

121 is Palindrome

कैसे काम करता है

  • हम संख्या को % और / से digit-by-digit उलटते हैं।
  • उलटी संख्या original के बराबर हो तो palindrome है।

सारांश

  • एक संख्या palindrome है अगर उलटी पढ़ने पर भी वैसी ही हो, जैसे 121 या 1331।
← Back to Java Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

💻 Live Code Editor

This page's programs are ready here — run them, edit them, and learn. No installation needed.
Powered by OneCompiler. The code loads into the editor automatically — press Run to see the output. If the editor does not open, open it in a new tab.