How to find a number is Armstrong or not using Java? So first of all what is an Armstrong number? An Armstrong number is a number in which the sum of cubes of the individual digits is equal to the given number. So by now you would have got a clear idea about what an Amstrong number means. We will now learn **Java Program to check Armstrong Number**. The program execution flow is very easy, just entering the input number for checking it is Armstrong or not. We have defined two variables `sum`

, `rem`

and initialized them to 0. `sum`

is used to store the value of the user input after it is cubed. Then `sum`

is compared with the `n`

digits, If they are same then the number is said to be Armstrong else not Armstrong.

**For Example:**

Let us think the user input is: 153 then 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153. So the given number is an Armstrong number.

You might also consider reading:

## Java Program to check Armstrong number

//Check whether a given number is armstrong number or not import java.io.*; import java.lang.*; class Armstrong { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int sum = 0, rem = 0; System.out.print("\nEnter a number : "); int n = Integer.parseInt(br.readLine()); int num = n; while(num!=0) { rem = num%10; sum = sum + (rem*rem*rem); num = num/10; } if(n == sum) System.out.println("\nGiven number is an armstrong number"); else System.out.println("\nGiven number is not an armstrong number"); } }

Output:

{ 1 comment… read it below or add one }

Thanks. Helped me a lot