Computer Science, asked by tsohan, 6 months ago

1
Write a program to classify Abundant, Deficient and perfect (integers). Between 1 to 100​

Answers

Answered by manas7083
0

Write a Java program to classify Abundant, deficient and perfect number (integers) between 1 to 10,000.

In number theory, an abundant number is a number for which the sum of its proper divisors is greater than the number itself.

Pictorial Presentation:

Java: Classify Abundant, deficient and perfect number (integers) between 1 to 10,000

Java: Classify Abundant, deficient and perfect number (integers) between 1 to 10,000

Java: Classify Abundant, deficient and perfect number (integers) between 1 to 10,000

Sample Solution:

Java Code:

import static java.util.stream.LongStream.rangeClosed;

public class Exercise2 {

public static void main(String[] args) {

int count_Deficient_no = 0;

int count_Perfect_no = 0;

int count_Abundant_no = 0;

for (long i = 1; i <= 10_000L; i++) {

long sum = proper_Divs_Sum(i);

if (sum < i)

count_Deficient_no++;

else if (sum == i)

count_Perfect_no++;

else

count_Abundant_no++;}

System.out.println("Number Counting [(integers) between 1 to 10,000]: ");

System.out.println("Deficient number: " + count_Deficient_no);

System.out.println("Perfect number: " + count_Perfect_no);

System.out.println("Abundant number: " + count_Abundant_no);}

public static Long proper_Divs_Sum(long num) {

return rangeClosed(1, (num + 1) / 2).filter(i -> num % i == 0 && num != i).sum();}}

Copy

Sample Output:

Number Counting [(integers) between 1 to 10,000]:

Deficient number: 7508

Perfect number: 4

Abundant number: 2488

bts (◍•ᴗ•◍)❤ exo

Similar questions