📘 Lesson · Lesson 49
Armstrong Number
Armstrong Number Program in Java
An Armstrong number equals the sum of its digits each raised to the power of the number of digits (e.g. 153 = 1+125+27).
Java Program
int num = 153, sum = 0, temp = num;
while (temp != 0) {
int d = temp % 10;
sum += d * d * d; // 3 digits -> power 3
temp /= 10;
}
System.out.println(num + (sum == num ? " is Armstrong" : " is Not Armstrong"));
Output
153 is Armstrong
How it Works
- Extract each digit, cube it (for a 3-digit number), and add.
- If the sum equals the number, it is Armstrong.
Summary
- An Armstrong number equals the sum of its digits each raised to the power of the number of digits (e.g. 153 = 1+125+27).
Armstrong Number Program in Java
एक Armstrong number अपने digits के योग के बराबर होती है जहाँ हर digit को digits की संख्या की power तक उठाया जाता है (जैसे 153 = 1+125+27)।
Java Program
int num = 153, sum = 0, temp = num;
while (temp != 0) {
int d = temp % 10;
sum += d * d * d; // 3 digits -> power 3
temp /= 10;
}
System.out.println(num + (sum == num ? " is Armstrong" : " is Not Armstrong"));
Output
153 is Armstrong
कैसे काम करता है
- हर digit निकालें, cube करें (3-digit के लिए), और जोड़ें।
- योग संख्या के बराबर हो तो Armstrong है।
सारांश
- एक Armstrong number अपने digits के योग के बराबर होती है जहाँ हर digit को digits की संख्या की power तक उठाया जाता है (जैसे 153 = 1+125+27)।
💻 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.