Question: 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

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!