This post shows how you can generate and display Armstrong numbers in Java with in the given range. A number is an Armstrong number if it is equal to the sum of its digit raised to the power of count of digits in the number.

**As example**– 371 = 3^{3} + 7^{3} + 1^{3} = 27 + 343 +1 = 371

Number of digits is 3 here so every digit is raised to the power of 3 and added. Since the calculated number is equal to the original number so 371 is an Armstrong number.

1634 = 1^{4} + 6 ^{4} + 3^{4} + 4^{4} = 1 + 1296 + 81 + 256 = 1634

#### Display Armstrong numbers within the given range – Java Program

import java.util.Scanner; public class ArmstrongNumber { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter start number for displaying Armstrong numbers - "); int start = sc.nextInt(); System.out.println("Enter end number for displaying Armstrong numbers - "); int end = sc.nextInt(); System.out.print("Armstrong numbers with in " + start + " and " + end + "- "); for(int i = start; i <= end; i++){ if(checkIfArmstrong(i)){ System.out.print(i + " "); } } sc.close(); } private static boolean checkIfArmstrong(int number){ // Converting to string and calculating length int numLength = (number+"").length(); int temp = number; int sum = 0; while(temp > 0 ){ int remainder = temp % 10; sum = sum + (int)Math.pow(remainder, numLength); temp = temp/10; } if(number == sum){ return true; }else{ return false; } } }

__Output__

Enter start number for displaying Armstrong numbers - 10 Enter end number for displaying Armstrong numbers - 10000 Armstrong numbers with in 10 and 10000- 153 370 371 407 1634 8208 9474

**Related Posts**

- Fibonacci Series Java Program
- Display Prime Numbers in Java
- How to Reverse a Number in Java
- Java Program to Swap Two Numbers Without Using Third Variable
- Java Programs For Displaying Patterns
- Java Program to Reverse Each Word in a String
- How to Read File in Java
- Bubble Sort Java Program

That’s all for the topic **Display Armstrong Numbers in Java**. If something is missing or you have something to share about the topic please write a comment.

**You may also like**