Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases A Beginners Guide

Authors: Andy Oppel

1st Edition

007160846X, 978-0071608466

More Books

Students also viewed these Databases questions

Question

Distinguish between filtering and interpreting. (Objective 2)

Answered: 1 week ago