Armstrong Number in Java

 

Program to Check Armstrong Number

Armstrong number is a number that is of three  integer digits, whose sum of the cubes

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 it’s an 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 it’s Armstrong

System.out.print(“armstrong”);

else

System.out.print(“not”);

}}

Armstrong Number in Java
Armstrong Number in Java
Armstrong Number in Java

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 be Armstrong; otherwise not. In this output, 153 is the Armstrong number, 255 and 155 are not.

Java Command Line Arguments

How To Take Input From User In Java