Question: Write a Java program that reads a positive, non-zero integer as input and checks if the integer is deficient, perfect, or abundant. A positive,

Write a Java program that reads a positive, non-zero integer as input


Write a Java program that reads a positive, non-zero integer as input and checks if the integer is deficient, perfect, or abundant. A positive, non-zero integer, N, is said to be perfect if the sum of its positive proper divisors (i.e.. the positive integers, other than N itself, that divide N exactly) is equal to the number itself. If this sum is less than N, the number is said to be deficient. If the sum is greater than N. the number is said to be abundant. The first few perfect numbers are 6, 28, 496, and 8128. Illustrations: Number 6 28 Factors of the number less than itself Sum of Factors 3,2.1 14, 7, 4, 2, 1 6 28 For example, the number 6 is perfect, since 6=1+2+3, the number 8 is deficient, since 8>1+2+4, while the number 12 is abundant, since 12

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Here is a Java program that reads a positive nonzero integer as input from the user and determines whether the number is deficient perfect or abundant import javautilScanner public class PerfectNumber public static void mainString args Scanner scanner new ScannerSystemin SystemoutprintInput N int num scannernextInt int sum 0 for int i 1 i num i if num i 0 sum i if sum num Systemoutprintlnnum is deficient else if sum num Systemoutprintlnnum is perfect else Systemoutprintlnnum is abundant In the program We take an input integer N from the user We calculate the sum of all positive proper divisors of N numbers less than N that divide N exactly Based on the comparison of the sum with N we determine ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!