π Introduction
In Java number programs, Abundant Number is an important topic often asked in BCA exams, viva, and interviews.
In this article, you will learn what an abundant number is, how to check it using Java, along with clear explanation and dry run.
π’ What Is an Abundant Number?
A number is called an Abundant Number if the sum of its proper divisors is greater than the number itself.
π Proper divisors are the divisors excluding the number itself.
π§ Example of Abundant Number
Example 1
Number = 12
Proper divisors = 1, 2, 3, 4, 6
Sum = 1 + 2 + 3 + 4 + 6 = 16
Since 16 > 12,
✅ 12 is an Abundant Number
Example 2
Number = 8
Proper divisors = 1, 2, 4
Sum = 7
Since 7 < 8,
❌ 8 is NOT an Abundant Number
π§© Algorithm to Check Abundant Number
Start
Read a number
Initialize
sum = 0Find all divisors from
1tonumber/2If divisor divides number completely, add it to sum
If
sum > number→ Abundant NumberElse → Not Abundant
End
π» Java Program to Check Abundant Number
import java.util.Scanner;
public class AbundantNumber {
public static void main(String[] args) {
int number, sum = 0;
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
number = sc.nextInt();
for (int i = 1; i <= number / 2; i++) {
if (number % i == 0) {
sum = sum + i;
}
}
if (sum > number) {
System.out.println(number + " is an Abundant Number");
} else {
System.out.println(number + " is NOT an Abundant Number");
}
}
}
π§ͺ Dry Run
Input
number = 12
sum = 0
| i | Divides 12? | sum |
|---|---|---|
| 1 | Yes | 1 |
| 2 | Yes | 3 |
| 3 | Yes | 6 |
| 4 | Yes | 10 |
| 6 | Yes | 16 |
Final Check
sum = 16 > 12
✅ 12 is an Abundant Number
π₯️ Output
Enter a number: 12
12 is an Abundant Number
π Types of Numbers (For Better Understanding)
| Type | Condition |
|---|---|
| Perfect Number | Sum of divisors = number |
| Deficient Number | Sum of divisors < number |
| Abundant Number | Sum of divisors > number |
π― Important Exam Points
Proper divisors exclude the number itself
Loop runs till
number/2Time Complexity: O(n)
Common examples: 12, 18, 20, 24
Comments
Post a Comment