Armstrong number



if given number equal to the power of each and every digit with length of the given number and sum the powered value.That is called Armstrong number.



Example-1:


Input    : n=153
Output   : Armstrong number    
Explain  : 13+53+33=153. The output value is equal to the input value.



Example-2:


Input    : n=1634
Output   : Armstrong number 
Explain  : 14+64+34+44=1634. The output value is equal to the input value.
 


Example-2:


Input    : n=52
Output   : Not a Armstrong number 
Explain  : 52+22=29. The output value is not equal to the input value.
 







Solution




public class Main
{
    public static void main(String [] args)
    {
        int n = 153;

        int temp = n, sum = 0;

        String s = "" + n;

        int len = s.length();

        while(temp != 0){

            sum = sum + (int)Math.pow(temp % 10,len);

            temp = temp/10;
        }

        if(n == sum){
        
            System.out.print("Armstrong number");
        }

        else{
              
            System.out.print("Not a Armstrong number");
        }
    }
}
n = 153

n = str(n)

k = 0

for i in range(len(n)):

    k += (int(n[i]))**3

if(int(n) == k):

    print("Armstrong number")

else:

    print("Not a Armstrong number")



Output



Armstrong number