Armstrong Number In Java Programming Language

Armstrong Number In Java is the number that is equal to the sum of all digits to the power of the total number of digits in that number. To understand better check this example given below:

Armstrong Number

Eg:- The Number 153 which is an Armstrong number

Let’s Prove that this number is Armstrong number:

Total digits in number = 3

1^3 = 1*1*1 = 1

5^3 = 5*5*5 = 125

3^3 = 3*3*3 = 9

S0, 153 = (1*1*1)+(5*5*5)+(3*3*3)

153= 1+125+27 , Hence Proved

Armstrong Number In Java Program Code:

public class Armstrong {

public static void main(String[] args) {

int num = 371, originalNum, rem, result = 0;

originalNum = num;

while (originalNum != 0)
{
rem = originalNum % 10;
result += Math.pow(rem, 3);
originalNum /= 10;
}

if(result == num)
System.out.println(num + " is an Armstrong number.");
else
System.out.println(num + " is not an Armstrong number.");
}
}

Still having difficulty to understand, then you can watch this video to understand Armstrong number program:

Also Check: Armstrong Number In C

Sending
User Review
5 (5 votes)

Add a Comment

Your email address will not be published. Required fields are marked *