Program to Check Armstrong Number
Armstrong number is that number which is of three integer digits, which sum of the cube
of its individual digits is equal to that number which we enter like 153, the cube of 1 and the cube of 5,
and the cube of 3 and the sum of both (1*1*1)+(5*5*5)+(3*3*3)=153 means its Armstrong number.
others are…..370,371,407, etc
class arm
{
public static void main(String aa[])
{
int number,sum=0,temp,remainder;
number=Integer.parseInt(aa[0]); //number enter by user(run time0
temp=number; //value assign to variable temp
while(temp!=0) //condition check if temp is not equal 0 then
{
remainder=temp%10; //show remainder
sum=sum+remainder*remainder*remainder; //calculation
temp=temp/10;
}
if(number==sum) //if the value of number and the sum are equal then its armstrong
System.out.print(“armstrong”);
else
System.out.print(“not”);
}}
Explanation…
In the above example, we enter the value(integer type). If the value is not equal to zero then the
calculation will start. After calculation, it checks the output if the number and the sum are equal then
the output will Armstrong otherwise not. In this output 153 is the Armstrong number, 255 and 155 are not.