Tuesday, March 10, 2015

Performing Binary Search on Java float Array



Performing Binary Search on Java float Array

import java.util.Arrays;
public class BinarySearchFloatArrayExample
{
public static void main(String[] args)
{
float floatArray[] = {1.23f,2.10f,4.74f,5.34f};
Arrays.sort(floatArray);float searchValue = 4.74f;
int intResult = Arrays.binarySearch(floatArray,searchValue);
System.out.println("Result of binary search of 4.74 is : " + intResult);
searchValue = 3.33f;
intResult = Arrays.binarySearch(floatArray,searchValue);
System.out.println("Result of binary search of 3.33 is : " + intResult);
   }
}

No comments:

Post a Comment