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.");         
   }

 

Share Your Comments
Previous C# Program to Print Pyramid From Console Application
Next Java Program to print Alphabets

About author

Aamir Shaikh
Aamir Shaikh 1370 posts

A Blogger, SEO Analyst and passionate Web Developer from India. Believes in hard work and continues working to achieve success.

View all posts by this author →

You might also like