On this page, we are going to learn how to write a Java programme to print an Armstrong number.

What is an Armstrong Number?

The Armstrong number is equal to the sum of its digit cubes.

For example, 0, 1, 153, 370, 371 and 407 are the Armstrong numbers.

Let's take a number from the given example above and understand how it is an Armstrong number.

153 = (1*1*1) + (5*5*5) + (3*3*3)

Find the cube values of each digit.
1 * 1 * 1 = 1
5 * 5 * 5 = 125
3 * 3 * 3 = 27
Add cube values and check if they are equal to the given number or not.

1 + 125 + 27 = 153

So, we can see that the addition of cube values of each digit is 153, which is equal to the Armstrong number 153.

Now, let's see the Java program implementation of an Armstrong number as given below.

Program 1: Check whether the number is Armstrong or not

Output

537 is not an Armstrong number. 370 is an Armstrong number.

Program 2: Check whether the number is Armstrong or not with user input

Output 1:

Enter 3 Digit Number: 285 285 is not an Armstrong number

Output 2:

Enter 3 Digit Number: 370 370 is an Armstrong number

That's all guys, hope this Java Program is helpful for you.

Happy Learning... 😀

Please share this article on social media to help others.

If you have any query or suggestion regarding this artical please share with us feedback@javabytechie.com