Java program to display armstrong numbers between intervals using function

Here's a Java program to display Armstrong numbers between intervals using a function:

public class ArmstrongNumber {
    public static void main(String[] args) {
        int low = 100;
        int high = 1000;
        System.out.printf("Armstrong numbers between %d and %d are: ", low, high);
        for (int i = low; i < high; i++) {
            if (isArmstrongNumber(i)) {
                System.out.print(i + " ");
            }
        }
    }

    public static boolean isArmstrongNumber(int number) {
        int sum = 0;
        int originalNumber = number;
        int digits = String.valueOf(number).length();
        while (number > 0) {
            int remainder = number % 10;
            sum += Math.pow(remainder, digits);
            number /= 10;
        }
        return sum == originalNumber;
    }
}
Source:ww‮‬w.theitroad.com

In this program, we first define the lower and upper limits of the interval we want to check for Armstrong numbers. We then call a function called isArmstrongNumber for each number in this interval, and print the numbers that satisfy the Armstrong number condition.

The isArmstrongNumber function takes an integer as input and returns a boolean indicating whether the input number is an Armstrong number or not. The function first calculates the number of digits in the input number, and then uses a while loop to extract each digit and raise it to the power of the number of digits. The sum of these powers is compared to the original number to determine whether it is an Armstrong number.

You can modify the values of low and high to check for Armstrong numbers in different intervals.