Easy ways to check Armstrong number in java

An Armstrong number is an n-digit number that is equal to the sum of the nth powers of its digits.

e.g –

Numbers 1 to 9 (1 digit, so to the power 1)

1^1 = 1, 2^1 = 2, 3^1 = 3

Number 371 (3 digit, so to the power 3)

371 is of 3 digits, so sum of each digits cube should be 371

3^3 + 7^3 + 1^3 = 27 + 343 + 1 = 371

Number 1634 (4 digit, so to the power 4)

1^4 + 6^4 + 3^4 + 4^4 = 1 + 1296 + 81 + 256 = 1634

Let’s see implementation in java

 

Content posted is based on learning or working experience, please leave comments if anything needs to be added or updated, discuss your queries on our facebook:qavalidation.com, Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: