IndexOutOfBoundsException.java 503 B

1234567891011121314
  1. /**
  2. * IndexOutOfBoundsException
  3. * Provides a nice message when we try to pick a number
  4. * that is outside of the number of elements in the heap.
  5. *
  6. * Written by Jonathan Landrum
  7. */
  8. public class IndexOutOfBoundsException extends RuntimeException {
  9. public IndexOutOfBoundsException(int n) {
  10. String bounds = n < 1 ? "less than 1." :
  11. "greater than the number of elements in the collection.";
  12. System.err.println("Invalid input. The number entered is " + bounds);
  13. }
  14. }