import java.util.List; public class Math { /** * Returns the minimum of the sublist of the given list * starting at the given index. * * @param list a list * @pre. list != null && list.size() > 0 * @param index begin index of the sublist * @pre. index <= 0 && index < list.size() * @return the minimum of the sublist of the given list * starting at the given index. */ public static int minimum(List list, int index) { int minimum; if (index == list.size() - 1) // base case: sublist contains one element { minimum = list.get(index); } else // recursive case: sublist contains more than one element { minimum = java.lang.Math.min(list.get(index), Math.minimum(list, index + 1)); } return minimum; } /** * Returns the sum of the elements of the sublist of the * given list starting at the given index. * * @param list a list * @pre. list != null * @param index begin index of the sublist * @pre. index <= 0 && index <= list.size() * @return the sum of the elements of the sublist of the * given list starting at the given index. */ public static int sum(List list, int index) { int sum; if (index >= list.size()) // base case: sublist is empty { sum = 0; } else // recursive case: sublist is empty { sum = list.get(index) + Math.sum(list, index + 1); } return sum; } }