# Disarium Number In Java

previous Next# Exploring Disarium Numbers: A Special Numerical Phenomenon

If you've ever delved into the fascinating world of number theory, you might have come across the term "Disarium number." In this blog, we unravel the mystery behind Disarium numbers, explore their unique properties, and provide a Java program to identify these intriguing numerical phenomena.

## Understanding Disarium Numbers

A Disarium number (also known as an "n-digit Disarium number") is a number that is equal to the sum of its digits each raised to the power of its respective position. Mathematically, a number "n" is a Disarium number if it satisfies the following equation:

`n = d`_{1}^{1} + d_{2}^{2} + d_{3}^{3} + ... + d_{k}^{k}

Where:

- "n" is the number itself.

- "d_{i}" represents the digits of the number (e.g., d_{1}, d_{2}, d_{3}, ...).

- "k" is the number of digits in the number.

For example, let's take the number 89:

`8`^{1} + 9^{2} = 8 + 81 = 89

As shown, 89 is a Disarium number because the sum of its digits, each raised to the power of its position, equals the number itself.

## Identifying Disarium Numbers in Java

Now, let's create a Java program to identify Disarium numbers within a given range. We'll define a function that checks each number in the range and determines if it meets the Disarium criteria:

```
import java.util.ArrayList;
import java.util.List;
public class DisariumNumbers {
public static void main(String[] args) {
int startRange = 1;
int endRange = 10000;
List<Integer> disariumNumbers = findDisariumNumbers(startRange, endRange);
System.out.println("Disarium numbers between " + startRange + " and " + endRange + ":");
for (int num : disariumNumbers) {
System.out.print(num + " ");
}
}
public static List<Integer> findDisariumNumbers(int start, int end) {
List<Integer> disariumNumbers = new ArrayList<>();
for (int num = start; num <= end; num++) {
if (isDisarium(num)) {
disariumNumbers.add(num);
}
}
return disariumNumbers;
}
public static boolean isDisarium(int num) {
int sum = 0;
int originalNum = num;
int numDigits = (int) Math.log10(num) + 1;
while (num > 0) {
int digit = num % 10;
sum += Math.pow(digit, numDigits);
num /= 10;
}
return sum == originalNum;
}
}
```

This Java program defines a function "isDisarium" that checks if a given number is a Disarium number by calculating the sum of its digits raised to their respective positions. The "findDisariumNumbers" function finds Disarium numbers within a specified range.

## Conclusion

Disarium numbers are a captivating mathematical phenomenon that offers a unique perspective on numerical patterns. They provide an exciting avenue for exploration in the world of number theory and can be identified using simple programming techniques, as demonstrated in our Java program. By understanding and identifying Disarium numbers, you gain insight into the intriguing relationships between digits and their positions in numerical sequences.