Armstrong Algorithm

The Armstrong Algorithm, also known as the Armstrong Number Algorithm, is a method used to determine if a given number is an Armstrong number or not. An Armstrong number, or narcissistic number, is a number that is equal to the sum of its own digits each raised to the power of the number of digits in the number. For example, the number 153 is an Armstrong number because 1^3 + 5^3 + 3^3 = 153. These numbers are named after Michael F. Armstrong, who is credited with discovering this property of numbers. The Armstrong Algorithm works by first counting the number of digits in the given number, which is usually done by converting the number to a string and measuring its length. Then, the algorithm iterates through each digit in the number, raising it to the power of the number of digits and summing the results. If the final sum is equal to the original number, then the number is an Armstrong number. Otherwise, it is not. This algorithm is often implemented using programming languages like Python, C++, and Java, and is commonly used in coding interviews and competitive programming to test the ability of the candidate to understand and implement such a concept.
package Others;

import java.util.Scanner;

/**
 * A utility to check if a given number is armstrong or not. Armstrong number is
 * a number that is equal to the sum of cubes of its digits for example 0, 1,
 * 153, 370, 371, 407 etc. For example 153 = 1^3 + 5^3 +3^3
 *
 * @author mani manasa mylavarapu
 */
public class Armstrong {
    static Scanner scan;

    public static void main(String[] args) {
        scan = new Scanner(System.in);
        int n = inputInt("please enter the number");
        boolean isArmstrong = checkIfANumberIsAmstrongOrNot(n);
        if (isArmstrong) {
            System.out.println("the number is armstrong");
        } else {
            System.out.println("the number is not armstrong");
        }
    }

    /**
     * Checks whether a given number is an armstrong number or not. Armstrong
     * number is a number that is equal to the sum of cubes of its digits for
     * example 0, 1, 153, 370, 371, 407 etc.
     *
     * @param number
     * @return boolean
     */
    public static boolean checkIfANumberIsAmstrongOrNot(int number) {
        int remainder, sum = 0, temp = 0;
        temp = number;
        while (number > 0) {
            remainder = number % 10;
            sum = sum + (remainder * remainder * remainder);
            number = number / 10;
        }
        return sum == temp;
    }

    private static int inputInt(String string) {
        System.out.print(string);
        return Integer.parseInt(scan.nextLine());
    }
}

LANGUAGE:

DARK MODE: