2016-06-13

Java program to check if a number is armstrong or Not

Similar Question:

     Print List of Armstrong number.


Solution:


class armstrong
{
public static void main(String args[])
{
int s=0,n=153,m,d;
m=n;
while(n>0)

{
d=n%10;
s=s+(d*d*d);
n=n/10;
}
if(m==s)
System.out.println("number is armstrong");
else
System.out.println("number is not armstrong");
}
}


No comments:

Post a Comment