Program to Check if a Number is an Abundant Number in Java

Abundant Number

An abundant number is a number for which the sum of its proper divisors is greater than the number itself. For example, 12 is an abundant number because its divisors (1, 2, 3, 4, 6) sum to 16, which is greater than 12.

We will explore a method to check if a given number is an abundant number using Java programming.

Method: Using a for Loop

We iterate through all numbers less than the given number to find its divisors and sum them up.

import java.util.Scanner;

public class Main {
    public static boolean isAbundant(int num) {
        int sum = 0;
        
        // Calculate the sum of proper divisors
        for (int i = 1; i <= num / 2; i++) {
            if (num % i == 0) {
                sum += i;
            }
        }
        
        return (sum > num);
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter a number: ");
        int num = scanner.nextInt();
        
        if (isAbundant(num))
            System.out.println(num + " is an Abundant number");
        else
            System.out.println(num + " is not an Abundant number");
        
        scanner.close();
    }
}
            

Output:

Enter a number: 12
12 is an Abundant number
Easy aceess next quctions
Getting Started

Positive or Negative number: C C++ Java Python

Even or Odd number: C C++ Java Python

Sum of First N Natural numbers: C C++ Java Python

Sum of N natural numbers: C C++ Java Python

Sum of numbers in a given range: C C++ Java Python

Greatest of two numbers: C C++ Java Python

Greatest of the Three numbers: C C++ Java Python

Leap year or not: C C++ Java Python

Prime number: C C++ Java Python

Prime number within a given range: C C++ Java Python

Sum of digits of a number: C C++ Java Python

Reverse of a number: C C++ Java Python

Palindrome number: C C++ Java Python

Armstrong number: C C++ Java Python

Armstrong number in a given range: C C++ Java Python

Harshad number: C C++ Java Python

Abundant number: C C++ Java Python

Friendly pair: C C++ Java Python