Java Program for finding Armstrong number






Here is a simple program in java to find whether the Entered number is an Armstrong number or not
Its a two step process Using a While Loop and If Else statements..
import java.util.*;
class ArmstrongPostslush
{
   public static void main(String args[])
   {
      int no, sum = 0, temp, t;

      Scanner in = new Scanner(System.in);
      System.out.println("Enter a number");      
      no = in.nextInt();

      temp = no;

      while( temp != 0 )
      {
         t = temp%10;
         sum = sum + t*t*t;
         temp = temp/10; 
      }

      if ( no == sum )
         System.out.println("The number is an armstrong number.");
      else
         System.out.println("The number is not an armstrong number.");         
   }

Previous Post Next Post