Purpose

This lab gives you more practice with recursion.

Lab

Write an overloaded method that displays the prime factors of a positive integer in descending order. For example,

Argument Value Display
100 5 5 2 2
17 17
111 37 3
3960 11 5 3 3 2 2 2

Use the following method headers:

public static void showFactors(int number)
private static void showFactors(int number, int factor)

The public method showFactors() should call the private method showFactors(), with a value of 2 for the second parameter. 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. You will not receive any credit for this lab for a solution that does not use recursion.

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. Submit your entire program, along with a capture of a sample run that includes the values listed above. Remember to provide documentation for your methods.

Sample dialog (user input in bold):

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!
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.