Deficient Number in Java — Definition, Examples and Program

Learn what a deficient number is in Java with definition, examples, and a simple program to check whether a number is deficient or not.

Deficient Number in Java — Definition, Examples and Program

A Deficient Number is a number for which the sum of its proper divisors (divisors excluding the number itself) is less than the number itself.

For example:

If the sum of proper divisors is exactly equal to the number, it becomes a Perfect Number. If the sum is greater, the number is Abundant.

How to Check Deficient Number?

Steps:

  1. Take a number from the user.
  2. Find all proper divisors (numbers less than it which divide it).
  3. Add all these divisors.
  4. If the sum is smaller than the number → It is a Deficient Number.

Example 1

Number: 21

Example 2

Number: 14

Java Program to Check Deficient Number


import java.util.Scanner;

public class DeficientNumber {

    public static boolean isDeficient(int num) {
        int sum = 0;

        for (int i = 1; i <= num / 2; i++) {
            if (num % i == 0) {
                sum += i;
            }
        }

        return sum < num;
    }

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

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

        if (isDeficient(num)) {
            System.out.println(num + " is a Deficient Number");
        } else {
            System.out.println(num + " is NOT a Deficient Number");
        }
    }
}

Sample Output


Enter a number: 9
9 is a Deficient Number

Enter a number: 12
12 is NOT a Deficient Number

Practice Challenges

  1. Write a program to print all deficient numbers from 1 to 100.
  2. Modify the program to also calculate how much the number is deficient (number − sum of divisors).
  3. Write a program to classify numbers as perfect, deficient, or abundant in a given range.

Deficient numbers are very common in number theory and are useful in mathematical classification problems. This Java program helps you analyze and explore them easily.