Answered step by step
Verified Expert Solution
Question
1 Approved Answer
(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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started