Menu
Topics Index
...
`

Is An Amstrong Number Or Not - Java Example Program


Is An Amstrong Number Or Not
class IsAnAmstrongNumber
{
    public static void main(String arg[])
    {
            
                int input = 370;
        
                int mod,sum = 0,temp;
        
                for(temp = input; input!= 0;input = input / 10)
                {
                    mod = input % 10;
        
                    sum = sum + (mod * mod * mod);
                }
        
                if(sum == temp)
                {
                    System.out.println(temp+" is an amstrong number");
                }
        
                else
                {
                    System.out.println(temp+" is not an amstrong number");
                }
            
    
    }
}
OUTPUT

370 is an amstrong number

DESCRIPTION

THINGS TO TRY
  • Check 1634 is an amstrong number or not
  • Check 43 is an amstrong number or not

© meritcampus 2019

All Rights Reserved.

Open In App