Armstrong numbers between 1 to 1000

Hey guys!! Welcome to flower brackets blog!! In this article let’s learn java program for armstrong numbers between 1 to 1000.

armstrong numbers between 1 to 1000

Armstrong numbers between 1 to 1000

Here’s the java program to print upto N armstrong numbers,

Also Read – Armstrong Number Java

public class ArmstrongNumberExample
{
public static void main(String[] args)
{
int number, temp, N = 1000, total = 0;
System.out.print("Armstrong numbers from 1 to N : ");
for(int a = 1; a <= N; a++)
{
number = a;
while(number > 0)
{
temp = number % 10;
total = total + (temp * temp * temp);
number = number / 10;
}
         if(total == a)
{
System.out.print(a + " ");
}
total = 0;
}
}
}

Output:

Armstrong numbers from 1 to N : 1 153 370 371 407

Related Posts