Written by Sai Sameera Thota on January 18, 2013 in Java > Programming

Java Program to check Armstrong number


Get our Latest updates delivered to your mailbox!

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;
			rem = num%10;
			sum = sum + (rem*rem*rem);
			num = num/10;
		if(n == sum)
			System.out.println("\nGiven number is an armstrong number");
			System.out.println("\nGiven number is not an armstrong number");

Download Source Code

Java Program Armstrong number

{ 1 comment… read it below or add one }

Aditya vaishnav July 19, 2013 at 7:13 am

Thanks. Helped me a lot


Leave a Comment

Previous post:

Next post: