-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbundantNumberCheck.java
More file actions
28 lines (25 loc) · 879 Bytes
/
AbundantNumberCheck.java
File metadata and controls
28 lines (25 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// 50. Write a program to check if a given number is an abundant number.
import java.util.Scanner;
public class AbundantNumberCheck {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = scanner.nextInt();
boolean isAbundant = isAbundantNumber(num);
if (isAbundant) {
System.out.println(num + " is an abundant number.");
} else {
System.out.println(num + " is not an abundant number.");
}
scanner.close();
}
public static boolean isAbundantNumber(int num) {
int sumOfDivisors = 0;
for (int i = 1; i <= num / 2; i++) {
if (num % i == 0) {
sumOfDivisors += i;
}
}
return sumOfDivisors > num;
}
}