January 03, 2025 |3.5K Views

    Java Program for Armstrong number

      Share  1 Like
    Description
    Discussion

    In this video we will write a JAVA Program to check given number is Armstrong's number or not. A number “N” is an Armstrong number if “ N ” is equal to the sum of all N’s integers raised to the power of the number of integers in N.
     

    What is an Armstrong Number?
    A positive integer of n integers is called Armstrong number of order n( order is the number of integers) if,
    abcd… = pow(a,n) + pow(b,n) + pow(c,n) + pow(d,n) + ….

    In this video we generate Armstrong number using two different methods:
    1. Using a While loop with a user-defined function
    2. Using temp variable

    Examples:
    1. Input number is 153.

    = > 1 * 1 * 1+ 5 * 5 * 5+ 3 * 3 * 3 = 153
    = > Output Yes, 153 is an Armstrong number.

    2. Input 120
    = > 1 * 1 * 1 +2 * 2 * 2 +0 * 0 * 0 = 9
    = > Output 120 isn't a Armstrong number.

    Algorithm: 
    Step 1: Input the number.
    Step 2: Find the total order( number of integers) of the given number.
    Step 3: For each number, find the number raised to the power of o where o is the order calculated in Step 2.
    Step 4: Compare the sum of all similar values with the given number.
    Step 5: Print the figures which satisfy the condition in Step 4.

    JAVA Program to check given number is Armstrong's number or not : https://www.geeksforgeeks.org/java-program-to-check-armstrong-number/