Java Code for Armstrong Number

Java code for Armstrong number. In the world of computer programming and number theory, Armstrong’s number is a fascinating concept for both beginners and experienced programmers. In this article we will write a Java program that can identify Armstrong numbers.

Armstrong Number

An Armstrong Number is a number that is equal to the sum of its digits each raised to the power of the number of digits in the number.

For example-153 is an armstrong number because 1^3 + 5^3 + 3^3 = 153

Java Program for Armstrong Number

Let’s write a Java code for Armstrong Number.

Output

Java Code for Armstrong Number

In the Above Java Program

  • Inside the main method using Scanner class program captures the user’s input and calls the isArmstrong method to check if the entered number meets the criteria of the armstrong number.
  • isArmstrong method performs the code logic. It calculates the number of digits in the number and than calculates the sum of digits of the number raised to the power of the number of digits in the number. It then compares this sum with the original number to determine if the given number is Armstrong’s number.

Writing a Java program to check Armstrong numbers is an excellent way to enhance understanding of loops, conditional operations, and mathematical operations in Java.

Happy Coding & Learning

See Also

3 thoughts on “Java Code for Armstrong Number”

Leave a Comment