In this Java program, you’ll learn how to Check Armstrong Number using the Java programming language.
Armstrong Number– It is the positive m-digit number which equals to the sum of the m th powers of their digits.
How to check Armstrong Number using JAVA Program?
Example 1:
RUN CODE SNIPPETpublic class Main
{
public static void main(String[] args)
{
int number = 153, originalNumber, remainder, result = 0;
originalNumber = number;
while (originalNumber != 0)
{
remainder = originalNumber % 10;
result += Math.pow(remainder, 3);
originalNumber /= 10;
}
if(result == number)
System.out.println(number + " is an Armstrong number.");
else
System.out.println(number + " is not an Armstrong number.");
}
}OUTPUT
153 is an Armstrong number.