Disarium Number in Java: Definition, Examples, and Complete Program

A detailed explanation of Disarium Numbers in Java with definition, examples, step-by-step logic, and a complete Java program. Ideal for beginners, students, and coding interview preparation.

Disarium Number in Java

A Disarium Number is a special number in which the sum of its digits, each raised to the power of their respective positions, equals the number itself. Disarium numbers are commonly asked in Java programming assignments and coding interviews because they test understanding of digit extraction and loop-based logic.

What Is a Disarium Number?

A number n with digits \(d_1, d_2, d_3...\) is called a Disarium Number if:

Sum = d₁¹ + d₂² + d₃³ + ...
If Sum == n → It is a Disarium Number
  

Examples

  • 135 → 1¹ + 3² + 5³ = 1 + 9 + 125 = 135
  • 89 → 8¹ + 9² = 8 + 81 = 89
  • 175 → 1¹ + 7² + 5³ = 1 + 49 + 125 = 175

Therefore, numbers like 89, 135, 175 are Disarium Numbers.

How Do We Check Disarium Numbers in Java?

The steps are:

  1. Count the digits of the number
  2. Extract digits one by one
  3. Raise each digit to the power of its position
  4. Sum the powered digits
  5. Compare the sum with the original number

Java Program to Check Disarium Number


import java.util.*;

public class DisariumNumber {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter a number: ");
        int num = sc.nextInt();

        int temp = num;
        int digits = Integer.toString(num).length();
        int sum = 0;

        while (temp > 0) {
            int digit = temp % 10;
            sum += Math.pow(digit, digits);
            digits--;
            temp /= 10;
        }

        if (sum == num) {
            System.out.println(num + " is a Disarium Number.");
        } else {
            System.out.println(num + " is NOT a Disarium Number.");
        }
    }
}

  

Example Walkthrough

Consider the number 135:

  • Digits = 1, 3, 5
  • Positions = 1, 2, 3
  • Calculation = 1¹ + 3² + 5³ = 135

Since the sum matches the number, 135 is a Disarium Number.

List of Known Disarium Numbers

  • 1
  • 2
  • 3
  • 89
  • 135
  • 175
  • 518
  • 598

Practice Challenge

Write a Java program to print all Disarium Numbers between 1 and 500. Apply the same logic inside a loop and display only the numbers that satisfy the Disarium condition.