Program to check armstrong number in Java























import java.util.*;

class ArmstrongNumber
{
   public static void main(String args[])
   {
      int n, sum = 0, temp, r;

      Scanner in = new Scanner(System.in);
      System.out.println("Enter a number to check if it is an armstrong number");      
      n = in.nextInt();

      temp = n;

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

      if ( n == sum )
         System.out.println("Entered number is an armstrong number.");
      else
         System.out.println("Entered number is not an armstrong number.");         
   }
}
Output
armstrong number

Discover more from PlusDigit

Subscribe to get the latest posts sent to your email.

One thought on “Program to check armstrong number in Java

  1. Armstrong Program in C++

    Armstrong number is a number that is the sum of its own digits each raised to the power of the number of digits is equal to the number itself.
    For example 153 is armstrong number, 132 is not prime number.Armstrong program in c++ is very simple and easy to write.

Comments are closed.

Discover more from PlusDigit

Subscribe now to keep reading and get access to the full archive.

Continue reading

AdBlock Detected!

Please disable your AdBlocker to access this website.

Once disabled, this message will disappear automatically.