Java program to print armstrong number from 1 to 1000

Let’s learn java program to print armstrong number from 1 to 1000.

java program to print armstrong number from 1 to 1000

Java program to print armstrong number from 1 to 1000

Java armstrong number is one of the common java interview question.

Also Read – multidimensional array in java

An armstrong number is sum of cube of its own digits. Here modulus and division operator is used alongside “for” loops and “if” condition.

Here’s the java program for armstrong number between 1 to 1000,

// armstrong number java
public class ArmstrongNumberDemo
{
   public static void main(String[] args)
   {
      int number, temp, total = 0;
      System.out.print("Armstrong number between 1 to 1000 : ");
      for(int a = 1; a <= 1000; 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 number between 1 to 1000 : 1 153 370 371 407