Question: 1. (45 pts) Implement search as specified below in two ways: using for loops, and using while(true) loops that are terminated when accessing the array
1. (45 pts) 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. // REQUIRES: a is sorted 77 EFFECTS: If a is null throws NullPointerException; else if x is not 77 in a, throws NotFoundException; else returns i such that a l -=x. public static int search (int[] a, int x) throws NullPointerException, NotFoundException Which implementation is better? Discuss. Note: For this question, besides the source code that you submit along with the homework solution, you also need to create a "homework4" folder in your cs.uco.edu account and put the source code there. 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
