Java Reference
In-Depth Information
Hint: This is a bit trickier than the preceding problem, because you must
keep track of how far the match is from the beginning of the sentence.
Make that value a parameter of a helper method.
΢ Exercise P13.6. Using recursion, find the largest element in an array.
public class DataSet
{
public DataSet(int[] values, int first, int
last) { È }
public int getMaximum() { È }
È
}
Hint: Find the largest element in the subset containing all but the last
element. Then compare that maximum to the value of the last element.
΢ Exercise P13.7. Using recursion, compute the sum of all values in an array.
public class DataSet
{
public DataSet(int[] values, int first, int
last) { È }
public int getSum() { È }
È
}
619
620
΢΢ Exercise P13.8. Using recursion, compute the area of a polygon. Cut off a
triangle and use the fact that a triangle with corners (x 1 , y 1 ), (x 2 , y 2 ), (x 3 ,
y 3 ) has area
| x 1 y 2
y 3 x 1 |
+
x 2 y 3
+
x 3 y 1
ɨ
y 1 x 2
ɨ
y 2 x 3
ɨ
2
 
Search WWH ::




Custom Search