How to check if a number is Armstrong number or not? || Java Programming Tutorials.

Опубликовано: 29 Июнь 2026
на канале: Learning and Teaching Coding
1,916
69

Lets see what is an Armstrong number.

A number is called Armstrong number if the following equation holds true for that number.

For example this is a 3 digit Armstrong number = 370

370 = (3*3*3) + (7*7*7) + (0*0*0)
= 27 + 343 + 0
= 370

=== When you run the program, the output will be: ===

1. First, given number (num)'s value is stored in another integer variable, originalNum. This is because, we need to compare the values of final number and original number at the end.

2. Then, a while loop is used to loop through (num) until it is equal to 0.
On each iteration, the last digit of num is stored in remainder.

3. Then, remainder is powered by 3 (number of digits) and added to result.

4. Then, the last digit is removed from num after division by 10.

Finally, result and num are compared. If equal, it is an armstrong number. If not, it isn't Armstrong number.

#LearningandTeachingCoding
#JavaProgrammingTutorials
#JavaPrograms