Sunday 23 September 2012

Java Program To Find Whether a Number is Armstrong

/* Simple Java program to find whether a number is an armstrong number or not */


class Armstrong
{
int sumcube(int x)
{
int dig,sum = 0;
while(x >= 1)
{
dig = x % 10;
sum = sum + dig * dig * dig;
x = x / 10;
}
return(sum);
}
void display(int n)
{
if(sumcube (n)==n)
System.out.println(n + " is Armstrong Number");
else
System.out.println(n + " is not Armstrong Number");
}
void disp()
{
int x = 0,y = 0;
for(int k = x;k <= y;k++)
if(sumcube (k)==k)
System.out.println(k);
}
}

0 comments:

Post a Comment