Question 1

Write a recursive definition for the following method:

/**
Precondition: n >= 1.
Displays the symbol '#' n times on one line
and then advances to the next line.
*/
public static void displaySharps(int n)

For example, the call displaySharps(3) is equivalent to

System.out.println("###");

If you have trouble writing this method, simplify it so that the output does not advance to the next line. For that simpler case, you need not worry about the distinction between print and println. In the simpler case, you use only print. After doing the simpler case, try to do the exercise as stated.

Question 2

A. Complete the definition of the following method. Your definition should be recursive.

/**
Precondition: n >= 0.
Returns 10 to the power n.
*/
public static int computeTenToThe(int n)

B. Complete the definition of the following method. Your definition should be recursive. Unlike the method in Question 1, this method does not restrict the sign or value of its argument. You can use the same technique you used for Question 2, but you should have one more recursive case for negative exponents. (Hints: 10n is 1/10n for negative values of n. Also, if n is negative, n is positive.)

/**
Precondition: n can be any int.
Returns 10 to the power n.
*/
public static int computeTenToThe(int n)
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.