Java Array class binarySearch(float[] a, float key) example
Array class binarySearch(float[] a, float key) method example
Array class binarySearch(float[] a, float key) method example. This example shows you how to use binarySearch(float[] a, float key) method.This method Searches the specified array of floats for the specified value using the binary search algorithm.
Here is the code:-
/**
* @Program that Searches the specified array of floats for the specified
* value using the binary search algorithm.
* binarySearch7Array.java
* Author:-RoseIndia Team
* Date:-15-May-2008
*/
import java.util.*;
public class binarySearch7Array {
public static void main(String[] args) {
//Creating a Float Array
float arr[]={1.6f,1.7f,1.8f,5.7f,1.6f};
//Searching the array
int i=Arrays.binarySearch(arr,1.6f);
//Displaying the element
System.out.println("The element "+arr[i]+" is found at index "+i);
}
} |
Output of the program:-
| The element 1.6 is found at index 0 |
|