The following program segment checks whether a number is an Abundant number or not. A number is said to be Abundant when the sum of its factors (excluding the number itself) is greater than the number. Example: factors of 12 are 1, 2, 3, 4, 6 and their sum is 16. Fill in the blanks with appropriate Java statements: void abundant(int n) { int s = 0; for( (i) __________ ; (ii) __________ ; i++) { if( (iii) __________ ) s = s + i; } if( (iv) __________ ) System.out.println("Abundant Number"); else System.out.println("Not Abundant Number"); }
Fill in blank (iv): if( __________ )
Topic: The abundance test
Try it
Pick an option and check your answer. The full worked answer is below either way.
Answer
(b) s > n.
The definition states that a number is abundant when the sum of its proper factors is GREATER than the number, so the test is s > n. For 12, s = 16 and 16 > 12, so 12 is abundant. Worth knowing the companion terms: s == n gives a PERFECT number (6 and 28, for example) and s < n gives a DEFICIENT number. Option (d) is an assignment, not a comparison, and would not compile.
s > n.