Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a java program that use\'s nested for loops to find all the three - digit

ID: 3680558 • Letter: C

Question

Create a java program that use's nested forloops to find all the three-digit Armstrong numbers. Armstrong numbers are three digit numbers such that the sum of the digits cubed is equal to the number itself.

For example, 153 is an Armstrong number because 1³ + 5³ + 3³ = 153

However, 294 is not, because 2³ + 9³ + 4³ = 801 (not 294).

In addition, your program should count how many multiplication operations the program performed. If your number of multiplication operations are bigger than mine, please think about how to reduce it, and try to modify your program to get the smallest number of multiplication operations.

The output should be like the following:'

Explanation / Answer

import java.util.Arrays;
import java.util.Scanner;
public class ArmstrongNumberDemo{

    public static void main(String args[]) {

        Scanner cmd = new Scanner(System.in);
        int count = 100000;
        int index = 0;
        for (int i = 2; i < count; i++) {
            if (isArmstrongNumber(i)) {
                System.out.printf("Armstrong number %d: %d %n", index, i);
                index++;
            }

        }
        cmd.close();
    }

    /**
     * Java Method to check if given number is Armstrong Number or not
     *
     * @param number
     * @return true, if Armstrong number, false otherwise.
     */
    public static boolean isArmstrongNumber(int number) {
        int sum = 0;
        int copyOfInput = number;
        while (copyOfInput != 0) {
            int lastDigit = copyOfInput % 10;
            sum += (lastDigit * lastDigit * lastDigit);
            copyOfInput /= 10;
        }

        if (sum == number) {
            return true;
        }
        return false;
    }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote