Selector.java - Defines a library of selection methods on arrays of [email protected] YOUR NAME([email protected] Dean Hendrix([email protected]@version public final

Selector.java - Defines a library of selection methods on...

This preview shows page 1 - 3 out of 4 pages.

/** * Defines a library of selection methods * on arrays of ints. * * @author YOUR NAME (email) * @author Dean Hendrix ([email protected]) * @version 9/4/2019 * */ public final class Selector { /** * Can't instantiate this class. * * D O N O T C H A N G E T H I S C O N S T R U C T O R * */ private Selector() { } /** * Selects the minimum value from the array a. This method * throws IllegalArgumentException if a is null or has zero * length. The array a is not changed by this method. */ public static int min(int[] a) throws IllegalArgumentException { if (a == null || a.length == 0) { throw new IllegalArgumentException(); } int min = a[0]; for (int i = 0; i < (a.length); i++) { if (a[i] < min) { min = a[i]; } } return min; } /** * Selects the maximum value from the array a. This method * throws IllegalArgumentException if a is null or has zero * length. The array a is not changed by this method. */ public static int max(int[] a) throws IllegalArgumentException { if (a == null || a.length == 0) { throw new IllegalArgumentException(); } int max = a[0]; for (int i = 0; i < (a.length); i++) { if (a[i] > max) { max = a[i]; } } return max; } /** * Selects the kth minimum value from the array a. This method
Image of page 1
* throws IllegalArgumentException if a is null, has zero length, * or if there is no kth minimum value. Note that there is no kth
Image of page 2
Image of page 3

You've reached the end of your free preview.

Want to read all 4 pages?

  • Spring '10
  • HENDRIX
  • Equals sign, The Return, ASCII

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes