## Theory

Let *a _{1}a_{2}a_{3}…a_{n}* a number of n digits, where

*a*are the digits of the number. The number will be called if

_{1}, a_{2}, a_{3},…a_{n}*a _{1}^{n}+a_{2}^{n}+a_{3}^{n}+a_{4}^{n}+…….+a_{n}^{n }= a_{1}a_{2}a_{3}…a_{n} *(the number itself)

There is only 1 digit in the number from 0 to 9. Now notice that

0^{1} = 0; 1^{1} = 1; 2^{1} = 2; 3^{1} = 3; 4^{1} = 4; 5^{1} = 5; 6^{1} = 6; 7^{1} = 7; 8^{1} = 8; 9^{1} = 9;

So these are all Armstrong numbers. But

1^{2}+0^{2} ≠ 10; 1^{2}+1^{2} ≠ 11; 1^{2}+2^{2} ≠ 12

So these three numbers and many more are not Armstrong. Here are a few more examples of Armstrong numbers:

1^{3}+5^{3}+3^{3} = 153; 3^{3}+7^{3}+0^{3} = 370; 3^{3}+7^{3}+1^{3} = 371; 4^{3}+0^{3}+7^{3} = 407

So 153, 370, 371 and 407 are also Armstrong numbers.

## Java Code

package com.physicsinfo; import java.util.Scanner; public class Main { public static void main(String args[]){ System.out.print("Enter the number you want to check for being Armstrong: "); Scanner sc = new Scanner(System.in); String str = sc.next(); int n = str.length(); char[] chr = new char[n]; int[] num = new int[n]; for (int i=0;i<n; i++){ chr[i] = str.charAt(i); num[i] = Character.getNumericValue(chr[i]); } double sum = 0; for(int j=0;j<n;j++){ sum = sum +Math.pow(num[j],n); } if (sum == Double.parseDouble(str)){ System.out.println("It's a Armstrong number."); } else{ System.out.println("It's not a Armstrong number."); } } }