Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment: In Java, write an overloaded method that displays the prime factors of a positive integer in descending order. Use the following method headers: public

Assignment: In Java, write an overloaded method that displays the prime factors of a positive integer in descending order.

Use the following method headers:

public static void showFactors(int number) private static void showFactors(int number, int factor) Note that Java does not have default values for parameters. The public method showFactors() should call the private method showFactors(), with a value of 2 for the second argument. So the public method should be written like the following example: 
public static void showFactors(int number) { showFactors(number, 2); } The overloaded method effectively gives a default value of 2 for the second argument. 

The private method showFactors() that you write must be RECURSIVE. Do not use any loops in the methods that you write.

Do not use any arrays or private data members in the methods that you write.

Write a driver program to test your methods.

Program Output:

Enter a number, and I will display its prime factors in descending order

(enter 0 to exit program): 100

The factors for 100: 5 5 2 2

Enter a number, and I will display its prime factors in descending order

(enter 0 to exit program): 17

The factors for 17: 17

Enter a number, and I will display its prime factors in descending order

(enter 0 to exit program): 111

The factors for 111: 37 3

Enter a number, and I will display its prime factors in descending order

(enter 0 to exit program): 3960

The factors for 3960: 11 5 3 3 2 2 2

Enter a number, and I will display its prime factors in descending order

(enter 0 to exit program): 0

Goodbye!

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

Oracle 12c SQL

Authors: Joan Casteel

3rd edition

1305251032, 978-1305251038

More Books

Students also viewed these Databases questions

Question

3 What are the aims of appraisal?

Answered: 1 week ago

Question

Explain the different types of marketing strategies.

Answered: 1 week ago

Question

Explain product positioning.

Answered: 1 week ago

Question

Explain Industrial market segment.

Answered: 1 week ago

Question

3. What might you have done differently

Answered: 1 week ago

Question

4. Did you rethink your decision?

Answered: 1 week ago