package test2; import java.util.ArrayList; import java.util.List; public class Utility2D { private Utility2D() { } /** * Returns the double value equal to 1 divided by x. For example, * *
* Utility2D.reciprocal(2) returns 0.5 ** * @param x a value * @return the quotient 1 divided by x * @throws ArithmeticException if x is equal to zero */ public static double reciprocal(int x) { if (x == 0) { throw new ArithmeticException(); } return 1.0 / x; } /** * Returns a list containing the elements [min, min + 1, min + 2, ..., max] * where min is the smaller value of a and b, and max is the larger value of * a and b. If a and b have the same value then the returned list contains * only one element and that element is equal to a. For example: * *
* Utility2D.interval(-3, 2) returns the list [-3, -2, -1, 0, 1, 2] ** * @param a one end of an interval * @param b the other end of an interval * @return the list containing the elements [min, min + 1, min + 2, ..., max] * where min is the smaller value of a and b, and max is the larger * value of a and b */ public static List
* For example: * *
* s t Test2I.zipper(s, t) * --------------------------------------------- * [1] [2] [1, 2] * [5, 7] [6, 8] [5, 6, 7, 8] * [1, 1, 1] [0, 0, 0] [1, 0, 1, 0, 1, 0] * [] [10, 9, 8] [10, 9, 8] * [-5, 7, 2] [99] [-5, 99, 7, 2] ** * @param s a non-null list * @param t a non-null list * @return the zipper of the lists s and t */ public static List