Question: Write it in java and please do it with proper indenting and comments Write a program that will determine if a users number is perfect.

Write it in java and please do it with proper indenting and comments

Write a program that will determine if a users number is perfect. A perfect number is defined as a number that equals the sum of its divisors, such as 6. The values 1, 2, and 3 are the only divisors of 6 (not counting the number itself) and they add up to 6. The divisors of 9 are 1 and 3, which equal 4 when added. So 9 is not perfect. Use the internet to find other perfect numbers for your testing.

Start by writing the code to pull out all of the divisors for a single number. (Use the modulus operator to find which numbers divide evenly into the given number.) As you find them, print them to the screen and keep a running total (sum). Compare your final total with the original number to see if it is perfect. Report to the screen if the number is perfect.

Put this entire code in a loop and allow the user to try additional numbers until they decide they are done. Have them input a negative value to end the program.

Note: Be sure to test multiple values in a row to make sure values from the users first number do not affect the results of their 2nd, 3rd, etc. number.

Output Example (User input is marked with >>>. Everything else is what you print to the screen.)

This program will tell you if a number if perfect or not. Please enter a number. (Enter a negative value to exit.)

>>>28

Divisor: 1 Sum: 1

Divisor: 2 Sum: 3

Divisor: 4 Sum: 7

Divisor: 7 Sum: 14

Divisor: 14 Sum: 28

28 equals 28. Your number is perfect!

This program will tell you if a number if perfect or not. Please enter a number. (Enter a negative value to exit.)

>>>16

Divisor: 1 Sum: 1

Divisor: 2 Sum: 3

Divisor: 4 Sum: 7

Divisor: 8 Sum: 15

16 does not equal 15. Your number is not perfect.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!