Kodekraftt
/Blog
/Deficient Number In Java Definition Examples And Program
Join Early AccessContact UsPrivacy Policy
Java BasicsOOPsDSA with JavaQuizzesInterview Preparation

© 2026 KodeKraftt. All rights reserved.

Build smarter. Learn more. Innovate better.

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:

  • 8 → Proper divisors = 1, 2, 4 → Sum = 7 (less than 8) → Deficient
  • 15 → Proper divisors = 1, 3, 5 → Sum = 9 (less than 15) → Deficient

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

  • Proper divisors: 1, 3, 7
  • Sum = 11
  • 11 < 21 → 21 is a Deficient Number

Example 2

Number: 14

  • Proper divisors: 1, 2, 7
  • Sum = 10
  • 10 < 14 → 14 is a Deficient Number

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.

You might also like

Check if Two Strings Are Rotations of Each Other in Java — Definition, Examples and Program

Learn how to check whether two strings are rotations of each other in Java using logical string comparison without using complex libraries.

Find the Shortest Word in a Sentence in Java — Definition, Examples and Program

Learn how to find the shortest word in a sentence in Java using a simple character-by-character approach without using split() or advanced string methods.

Abundant Number in Java — Definition, Examples and Program

Learn what an abundant number is in Java with definition, examples, and a clean program to check whether a number is abundant or not.

Concatenate Two Strings in Java Without Using + Operator — Examples and Program

Learn how to concatenate two strings in Java without using the + operator. This blog explains the logic with examples, a Java program, and practice challenges.

Check if a String is Empty or Null in Java — Definition, Examples and Program

Learn how to check whether a string is null or empty in Java. This blog explains the difference, common mistakes, examples, and a safe Java program with practice challenges.

Convert String to Uppercase in Java Without Using String Library

Learn how to convert a string to uppercase in Java without using built-in String methods. This blog explains the ASCII-based logic with examples, a Java program, and practice challenges.