Software & Finance





Java - Find Armstrong Number





An I have given here the program for finding armstrong number of a three digits number.

 

The condition for armstrong number is,

Sum of the cubes of its digits must equal to the number itself.

 

For example, 407 is given as input.

4 * 4 * 4 + 0 * 0 * 0 + 7 * 7 * 7 = 407 is an armstrong number.

 

Source Code


import java.lang.*;

import java.util.*;

import java.io.*;

 

 

class ArmstrongNumber

{

   public static void main(String[] args)

   {     

      System.out.println("List of Armstrong Numbers between (100 - 999):");

 

      for(int i = 100; i <= 999; i++)

      {

         int a = i / 100;

         int b = (i - a * 100) / 10;

         int c = (i - a * 100 - b * 10);

 

         int d = a*a*a + b*b*b + c*c*c;

 

         if(i == d)

            System.out.format("%d\n", i); 

      }

   }

}

Output


 

List of Armstrong Numbers between (100 - 999):
153
370
371
407