KnowledgeBoat Logo

Java Number Programs (ISC Classes 11 / 12)

An Abundant number is a number for which the sum of its proper factors is greater than the number itself. Write a program to input a number and check and print whether it is an Abundant number or not.

Example:

Consider the number 12.

Factors of 12 = 1, 2, 3, 4, 6 Sum of factors = 1 + 2 + 3 + 4 + 6 = 16

As 16 > 12 so 12 is an Abundant number.

Java

Java Iterative Stmts

109 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");
    }
}

Output

BlueJ output of An Abundant number is a number for which the sum of its proper factors is greater than the number itself. Write a program to input a number and check and print whether it is an Abundant number or not. Example: Consider the number 12. Factors of 12 = 1, 2, 3, 4, 6 Sum of factors = 1 + 2 + 3 + 4 + 6 = 16 As 16 > 12 so 12 is an Abundant number.BlueJ output of An Abundant number is a number for which the sum of its proper factors is greater than the number itself. Write a program to input a number and check and print whether it is an Abundant number or not. Example: Consider the number 12. Factors of 12 = 1, 2, 3, 4, 6 Sum of factors = 1 + 2 + 3 + 4 + 6 = 16 As 16 > 12 so 12 is an Abundant number.

Answered By

40 Likes