Professional Documents
Culture Documents
INT201 OOP Labsheet 9 2022 2
INT201 OOP Labsheet 9 2022 2
Exercise 1
Write a recursive function printLine() that takes a parameter n of type integer and prints n
stars separated by a space on a single line. For example, calling printLine(5) will print the
following line:
* * * * *
Exercise 2
Write a recursive method for the following function which computes x y:
{
1 if y=0
x if y=1
power ( x , y ) = x∗power ( x , y−1 ) if y >1
1
if y <0
power ( x ,− y )
Test your method by reading x, and y and compute xy. Try with 43 and 5-2.
Exercise 3
Write a recursive method that computes the product of two integers mn by adding m repeatedly n times.