Start Coding Now
🔢 Number Programsintermediate1 methods

Armstrong Number in Java

Check if a number is an Armstrong number. A number is Armstrong if the sum of its digits raised to the power of digits equals the number.

Last updated: 11 January 2026

Method 1: Using While Loop

Check for 3-digit number (or n-digit).

public class Armstrong {
    public static void main(String[] args) {
        int number = 153, originalNumber, remainder, result = 0;
        originalNumber = number;

        while (originalNumber != 0) {
            remainder = originalNumber % 10;
            result += Math.pow(remainder, 3);
            originalNumber /= 10;
        }

        if(result == number)
            System.out.println(number + " is an Armstrong number.");
        else
            System.out.println(number + " is not an Armstrong number.");
    }
}
Output:
153 is an Armstrong number.

Explanation

1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153.

Frequently Asked Questions

Try This Program

Copy this code and run it in our free online Java compiler.

Open Java Compiler