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:
- Take a number from the user.
- Find all proper divisors (numbers less than it which divide it).
- Add all these divisors.
- 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
- Write a program to print all deficient numbers from 1 to 100.
- Modify the program to also calculate how much the number is deficient (number − sum of divisors).
- 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.