# Java Program to Check Armstrong or Not

## Check Armstrong or Not

To check whether a number is an Armstrong number or not Armstrong number in Java Programming, you have to ask to the user to enter the number, now check whether the entered number is an Armstrong number or not as shown in the following program.

To check whether any positive number is an Armstrong number or not, you have to perform the summation of, three times multiplication of, all the digits present in the number, if the summation result is equal to the actual number then the number will be an Armstrong number, otherwise the number will not be an Armstrong number, following is the example :

• Since 153 = 1*1*1 + 5*5*5 + 3*3*3. So 153 is an Armstrong number
• Since 12 is not equal to 1*1*1+2*2*2. So 12 is not an Armstrong number

## Java Programming Code to Check Armstrong or Not

Following Java Program ask to the user to enter any positive integer to find whether it is an Armstrong number or not, then display the result on the screen:

```/* Java Program Example - Check Armstrong or Not */

import java.util.Scanner;

public class JavaProgram
{
public static void main(String args[])
{
int n, nu, num=0, rem;
Scanner scan = new Scanner(System.in);

System.out.print("Enter any Positive Number : ");
n = scan.nextInt();

nu = n;

while(nu != 0)
{
rem = nu%10;
num = num + rem*rem*rem;
nu = nu/10;
}
if(num == n)
{
System.out.print("Armstrong Number");
}
else
{
System.out.print("Not an Armstrong Number");
}
}
}```

When the above Java Program is compile and executed, it will produce the following output. Above Java Programming Example Output (Armstrong Number):

Above Java Programming Example Output (Not Armstrong Number):

### Same Program in Other Languages

You may also like to learn and practice the same program in other popular programming languages:

Tools
Calculator