Java Program to Check Armstrong Number

Write a java program to check Armstrong number. In this program, we are going to write a java code which checks whether a number is Armstrong or not.

Let’s first understand what is Armstrong number?

What is Armstrong number?

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

For example – 153, 371 is an Armstrong number.

Example 1: 153 has 3 digits.

153 : 13 + 53 + 33 = 153

Example 2 – Take an example of 6 which has 1 digit.

6: 61 = 6 It’s an Armstrong number

Example 3 – Take another example let’s say 15, it has 2 digits.

15 : 12 + 52 = 26

So 15 is not an Armstrong number.

Example 4 – This time let’s take bigger number 1634, it has 4 digits.

1634 : 14 + 64 + 34 + 44 = 1634

It’s an Armstrong number.

How to Check whether a Number is Armstrong or Not

i) First, count number of digits of a number.
ii) Then, Calculate the sum of nth power of it’s digit.
iii) After that, Compare sum of nth power of it’s digit and original number. If original number and sum of nth power of it’s digit is same then it’s an Armstrong number otherwise it’s not.

Subscribe Our Tutorials

Get Latest Updates on Facebook

Java Program to Check Armstrong Number

Java Program to Check Armstrong Number

 

Java Program to Check Armstrong Number

We have discussed, What is an Armstrong number and how to check whether a number is Armstrong or not. Let’s write a java code which takes an input number and checks whether an input number is Armstrong or not.

 

More Programming Questions

Binary search in java

Java program to find first non-repeated character of a string

About WebRewrite

I am technology lover who loves to keep updated with latest technology. My interest field is Web Development.
Tagged , , , . Bookmark the permalink.