Java program to check armstrong number

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

Java programming code

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

Download Armstrong number program class file.

Output of program:
armstrong number

Using one more loop in the above code you can generate armstrong numbers from 1 to n(say) or between two integers (a to b).