Question: (java) Implement search as specified below in two ways: using for loops, and using while(true) loops that are terminated when accessing the array raises IndexOutOfBoundsException.
(java)
- Implement search as specified below in two ways: using for loops, and using while(true) loops that are terminated when accessing the array raises IndexOutOfBoundsException. Which implementation is better? Discuss
// REQUIRES: a is sorted
// EFFECTS: If a is null throws NullPointerException; else if x is not
// in a, throws NotFoundException; else returns i such that a[i]==x.
public static int search (int[] a, int x)
throws NullPointerException, NotFoundException
Which implementation is better? Discuss
*note
Implement the two static methods with names searchForLoop and searchWhileLoop, respectively, in a class named Searches. You may also need to define new exception types for the implementation.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
