Mar 19, 2010

JAVA Program to to find whether the given number is Armstrong or not

class Armstrong
{
public static void main(String[] args)
{
int n=143,temp,a=0,i=1;
temp=n;
while(i>0)
{
i=n%10;
a=(i*i*i)+a;
n=n/10;
}
if(a==temp)
System.out.println("the given number is armstrong");
else
System.out.println("the given number is not armstrong");
}
}
Download this program Here

1 comment:

  1. Output:
    the given number is not Armstrong.

    Armstrong means if the sum of cubes of each digit in a number is equals to the actual number.
    for example 153

    ReplyDelete