Java Program to Check Armstrong Number

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 SNIPPET
public 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.

Share:

Leave A Reply

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

You May Also Like

In this Java program, we will learn how to find the GCD of two numbers using Java.  GCD (Greatest Common...
  • Java
  • December 3, 2024
In this Java Program, you’ll learn how to swap two numbers using the Java programming language.  How to Swap Two...
  • Java
  • December 2, 2024
In this Java program , we will learn how to Find Largest Element in an Array in your Java program.   How to Find Largest Element...
  • Java
  • December 2, 2024