WRITE A PROGRAM TO CHECK WHETHER A NUMBER IS ARMSTRONG NUMBER OR NOT IN JAVA

class ArmstrongNumber 

{

    public static void main(String args[]) 

    {

        int n, temp , r, s=0 ;

        n=Integer.parseInt(args[0]);

        temp = n;

        while (temp != 0)

       {

            r = temp % 10;

            s = s + (r * r * r);

            temp = temp / 10;

        }

        if (n== s)

       {

            System.out.println(” It is an Armstrong Number”);

        } 

else

       {

            System.out.println(” It is not an Armstrong Number”);

        }

    }

}  

  • OUTPUT:
armstongjava.JPG

Leave a Comment

Your email address will not be published. Required fields are marked *