Let’s learn 4 digit armstrong number in java.

## 4 Digit Armstrong number in java

Now let’s learn armstrong number in java of 4 digits code with an example. Here’s the java program that checks whether the given 4 digit number is 4 digit armstrong number or not.

public class ArmstrongNumberDemo { public static void main(String[] args) { int num = 9474, realNumber, remainder, output = 0, a = 0; realNumber = num; for(;realNumber != 0; realNumber /= 10, ++a); realNumber = num; for(;realNumber != 0; realNumber /= 10) { remainder = realNumber % 10; output += Math.pow(remainder, a); } if(output == num) { System.out.println(num + " is an Armstrong number."); } else { System.out.println(num + " is not an Armstrong number."); } } }

**Output:**

9474 is an Armstrong number.

Also read – do while loop in java