Abundant Number in Java — Definition, Examples and Program
An Abundant Number is a number for which the sum of its proper divisors (divisors excluding the number itself) is greater than the number.
For example:
- 12 → Proper divisors = 1, 2, 3, 4, 6 → Sum = 16 (greater than 12) → Abundant
- 18 → Proper divisors = 1, 2, 3, 6, 9 → Sum = 21 (greater than 18) → Abundant
Such numbers are also known as excessive numbers because the sum of divisors exceeds the number.
How to Check Abundant Number?
Steps:
- Take a number as input.
- Find all of its proper divisors.
- Add all the divisors.
- If the sum is greater than the number → It is an Abundant Number.
Example 1
Number: 12
- Proper divisors: 1, 2, 3, 4, 6
- Sum = 1 + 2 + 3 + 4 + 6 = 16
- 16 > 12 → 12 is an Abundant Number
Example 2
Number: 20
- Proper divisisors: 1, 2, 4, 5, 10
- Sum = 22
- 22 > 20 → 20 is an Abundant Number
Java Program to Check Abundant Number
import java.util.Scanner;
public class AbundantNumber {
public static boolean isAbundant(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 (isAbundant(num)) {
System.out.println(num + " is an Abundant Number");
} else {
System.out.println(num + " is NOT an Abundant Number");
}
}
}
Sample Output
Enter a number: 18
18 is an Abundant Number
Enter a number: 15
15 is NOT an Abundant Number
Practice Challenges
- Write a program to print all abundant numbers between 1 and 100.
- Modify the program to display the abundance value (sum of divisors − number).
- Write a program to check whether a number is perfect, deficient, or abundant.
Abundant numbers are useful in number theory, divisor analysis, and classification of integers. With this program, you can easily check and explore them in Java.