# Armstrong Number in Java

An Armstrong number is a positive m-digit number that is equal to the sum of the mth powers of their digits. It is also known as pluperfect, or Plus Perfect, or Narcissistic number. It is an OEIS sequence A005188.

For example this is a 3 digit Armstrong number

```370 = 33 + 73 + o3
= 27 + 343 + 0
= 370```

## Armstrong Number in Java

``````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

The output of Armstrong number in java will show below for your reference.

``153 is an Armstrong number.``

## Armstrong Number in Java

Now, We can find the Armstrong number in java for n digits.

``````public class Armstrong {

public static void main(String[] args) {

int number = 8208, originalNumber, remainder, result = 0, n = 0;

originalNumber = number;

for (;originalNumber != 0; originalNumber /= 10, ++n);

originalNumber = number;

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

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

## Output

The output will display below for your reference.

``8208 is an Armstrong number.``