Java program to check armstrong number

August 21, 2014 , 0 Comments

This java program checks if a number is armstrong or not.

import java.util.*; 
class ArmstrongNumber
   public static void main(String args[])
      int n, sum = 0, temp, r;
      Scanner in = new Scanner(;
      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.");
         System.out.println("Entered number is not an armstrong number.");         

Java program to check armstrong number

Hope we are able to explain you jJava program to check armstrong number, if you have any questions or suggestions please write to us using contact us form.(Second Menu from top left).

Please share us on social media if you like the tutorial.

Prakash Hari Sharma
I'm a software developer and Java enthusiast. I like clean and modular code, enjoy Agile projects and have a passion for trying out new things. I try to learn and teach every day, and occasionally I'm even able to blog about it. :)