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

Java is a popular programming language that is used to develop a wide range of applications. If you are a...
  • Java
  • March 6, 2023
Java is a programming language and computing platform that is used to create various types of applications. It is used...
  • Java
  • March 6, 2023
In this post, you’ll learn how to download and install JUnit in Eclipse so that you can use in your...
  • Java
  • October 9, 2022