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.

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:

Such numbers are also known as excessive numbers because the sum of divisors exceeds the number.

How to Check Abundant Number?

Steps:

  1. Take a number as input.
  2. Find all of its proper divisors.
  3. Add all the divisors.
  4. If the sum is greater than the number → It is an Abundant Number.

Example 1

Number: 12

Example 2

Number: 20

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

  1. Write a program to print all abundant numbers between 1 and 100.
  2. Modify the program to display the abundance value (sum of divisors − number).
  3. 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.