Write a Java Program to Display Armstrong Number Between Two Intervals

Java Program to Display Armstrong Number Between Two Intervals

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn Java programming concepts. You can learn Java  language at your own speed and time. One can learn concepts of Java language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Java Program to Display Armstrong Number Between Two Intervals
Java Program to Display Armstrong Number Between Two Intervals

ls

PROGRAM: Java Program to Display Armstrong Number Between Two Intervals

/* Java Program to Display Armstrong Number Between Two Intervals */

class Main {
public static void main(String[] args) {

int low = 999, high = 99999;

for(int number = low + 1; number < high; ++number) {
int digits = 0;
int result = 0;
int originalNumber = number;

// number of digits calculation
while (originalNumber != 0) {
originalNumber /= 10;
++digits;
}

originalNumber = number;

// result contains sum of nth power of its digits
while (originalNumber != 0) {
int remainder = originalNumber % 10;
result += Math.pow(remainder, digits);
originalNumber /= 10;
}

if (result == number) {
System.out.print(number + ” “);
}
}
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *