WHAT'S NEW?

Armstrong Number Program in Java

class ArmstrongNumber 
{
public static void main(String[] args) 
{
int num=153;
int z=num;
int remainder=0,sum=0;

while (num>0)
{
remainder=num%10;
sum=sum+(remainder*remainder*remainder);
num=num/10;

}

if (sum==z)
{
System.out.println(""+z+" is an Armstrong Number");
}
else
{
System.out.println(""+z+" is not an Armstrong Number");
}

}
}


An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself.
 For example, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371.

0 comments:

Post a Comment