PACKAGE SOLUTION TO ALL THE EXERCISES


Exercise 1: What is the output of the following program?
Exercise 2: Write a recursive void method that has one parameter that is an integer and that writes to the screen the number of asterisks '*' given by the argument. The output should be all on one line. You can assume the argument is positive.
Exercise 3: Write a recursive void method that has one parameter, which is a positive integer. When called, the method writes its argument to the screen backward.That is, if the argument is 1234, it outputs the following to the screen: 4321
Exercise 4: Write a recursive void method that takes a single (positive) int argument n and writes the integers 1, 2, 3, . . . , n to the screen.

Exercise 5:Write a recursive void method that takes a single (positive) int argument n and writes integers n, n-1, . . . , 3, 2, 1 to the screen. Hint: The solution for Exercise 4 and this exercise vary by an exchange of as little as two lines.
Exercise 6: If your program produces an error message that says stack overflow, what is likely source of the error?
Exercise 7: Write an iterative verison of the method cheers defined in Exercise 1.
Exercise 8: Write an iterative version of the method defined in Exxercise 2.
Exercise 9: Write an iterative version of the method defined in Exercise 3.
Exercise 10: Trace the recursive solution you made to Exercise 4.
Exercise 11: Trace the recursive solution you made to Exercise 5
Exercise 12:What is the output of the following program?
Exercise 13: What is the output of the following program? What well-known mathematical method is rose?
Exercise 14: Redefine the method power() so that it also works for negative exponents. To do this, you also have to change the type of the value returned to double.The method heading for the redefined version of power is as follows:
Exercise 15: Write a recursive definition for the following method:
Exercise 16
Exercise 17
Exercise 18
Powered by