adding old solved challenges

This commit is contained in:
2024-10-15 11:03:57 -04:00
parent fa5ac5e089
commit 7ecd444efb
107 changed files with 1056 additions and 0 deletions
Binary file not shown.
+22
View File
@@ -0,0 +1,22 @@
public class ThePerfectNumber {
public static void main(String[] args) {
int[] randNums = { 2, 5, 6, 15, 23, 26, 34, 53, 343, 2454, 28 };
for (int number : randNums) {
if (isPerfect(number)) {
System.out.println(number + " is a perfect number");
} else {
System.out.println(number + " is NOT a perfect number");
}
}
}
private static boolean isPerfect(int num) {
int total = 0;
for (int i = 1; i <= num / 2; i++) {
if (num % i == 0) {
total += i;
}
}
return total == num;
}
}