# Program for Armstrong Number in Java

Here you will get program for armstrong number in java.

A number which is equal to the sum of its digits raised to the power n is called armstrong number. Here n is the total digits in the given number.

**Example:** 9 is an armstrong number as n = 1 and 9^{1 }= 9.

153 is an armstrong number as n = 3 and 1^{3} + 5^{3 }+^{ }3^{3 }= 1 + 125 + 27 = 153.

## Program for Armstrong Number in Java

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
package com; import java.util.Scanner; public class ArmstrongNumberJava { public static void main(String args[]) { int n, m, p = 0, len; Scanner sc = new Scanner(System.in); System.out.println("Enter a number:"); n = sc.nextInt(); m = n; //finding total digits in number len = String.valueOf(n).length(); while(m!=0) { p = p + (int)Math.pow(m%10, len); m = m/10; } if(p == n){ System.out.println("Armstrong Number"); } else{ System.out.println("Not Armstrong Number"); } } } |

**Output**

*Enter a number:*

*8208*

*Armstrong Number*

Comment below if you are facing any difficulty to understand concept of armstrong number in java.