📘 Lesson  ·  Lesson 49

Armstrong Number

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)।
← Back to Java Tutorial
🔗

Share this topic with a friend

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

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

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

\n