Abundant Number Check in Java: Explanation & Practice

Check if sum of proper divisors exceeds the number

Problem summary

An abundant number has proper divisors (excluding itself) that sum to more than the number.

Starter code

public class Main {
    public static void main(String[] args) {
        int number = 12; // Test case 1
        
        // Check if abundant
        // Print: Is abundant: <true/false>
    }
}

Expected output and test cases

  • 12: 1+2+3+4+6=16>12
    Is abundant: true
  • 15: 1+3+5=9<15
    Is abundant: false
  • 24: 1+2+3+4+6+8+12=36>24
    Is abundant: true

Hints

  1. Find all divisors from 1 to n/2
  2. Sum the divisors
  3. Compare sum with original number

Related Control Flow exercises

Practice all Control Flow exercises · Run this idea in the Java compiler