Java Array class binarySearch(double[] a, int fromIndex, int toIndex, double key) example
Array class binarySearch(double[] a, int fromIndex, int toIndex, double key) method example
Array class binarySearch(double[] a, int fromIndex, int toIndex, double key) method example. This method Searches a range of the specified array of doubles for the specified value using the binary search algorithm
Here is the code:-
/**
* @Program that Searches a range of the specified array of doubles for the
* specified value using the binary search algorithm.
* binarySearch6Array.java
* Author:-RoseIndia Team
* Date:-15-May-2008
*/
import java.util.*;
public class binarySearch6Array {
public static void main(String[] args) {
//Creating a Double Array
double arr[]={1.6,5.6,7.8,4.5,7.8,6.7};
//Searching the array
int i=Arrays.binarySearch(arr,2,5,7.8);
//Displaying the element
System.out.println("The element "+arr[i]+" is found at index "+i);
}
} |
Output of the program:-
| The element 7.8 is found at index 4 |
|