Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a method called perfectNumbers that accepts an integer maximum as its parameter and prints all perfect numbers up to and including that maximum. A

Write a method called perfectNumbers that accepts an integer maximum as its parameter and prints all "perfect numbers" up to and including that maximum. A perfect number is an integer that is equal to the sum of its proper factors, that is, all numbers that evenly divide it other than itself. For example, 28 is a perfect number because 1 + 2 + 4 + 7 + 14 = 28. The call perfectNumbers(500); should produce the following output:

Perfect numbers up to 500: 6 28 496 

Your program should be called FindPerfectNumbers.java

If a negative number is given to perfectNumbers, an IllegalArgumentException should be thrown.

HINT: Break the problem up into smaller sub-problems.

Write code to determine whether a given integer is a perfect number.

Write code to find all perfect numbers in a given range using the code you wrote in the first sub-problem.

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

Step: 3

blur-text-image

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

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions

Question

What is the environment we are trying to create?

Answered: 1 week ago

Question

How would we like to see ourselves?

Answered: 1 week ago