KnowledgeBoat Logo

Computer Applications

An abundant number is a number for which the sum of its proper divisors (excluding the number itself) is greater than the original number. Write a program to input number and check whether it is an abundant number or not.
Sample input: 12
Sample output: It is an abundant number.
Explanation: Its proper divisors are 1, 2, 3, 4 and 6
Sum = 1 + 2 + 3 + 4 + 6 = 16
Hence, 12 is an abundant number.

Java

Java Iterative Stmts

9 Likes

Answer

import java.util.Scanner;

public class KboatAbundantNumber
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter the number: ");
        int n = in.nextInt();
        int sum = 0;
        
        for (int i = 1; i < n; i++) {
            if (n % i == 0)
                sum += i;
        }
        
        if (sum > n)
            System.out.println(n + " is an abundant number.");
        else
            System.out.println(n + " is not an abundant number.");
    }
}

Variable Description Table

Program Explanation

Output

BlueJ output of An abundant number is a number for which the sum of its proper divisors (excluding the number itself) is greater than the original number. Write a program to input number and check whether it is an abundant number or not. Sample input: 12 Sample output: It is an abundant number. Explanation: Its proper divisors are 1, 2, 3, 4 and 6 Sum = 1 + 2 + 3 + 4 + 6 = 16 Hence, 12 is an abundant number.

Answered By

5 Likes


Related Questions