Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.util.Arrays;
- class BinarySearch
- {
- static int i;
- public static void main(String[] args)
- {
- Scanner a = new Scanner (System.in);
- System.out.println("Enter a number to find its position in the array.");
- int n = a.nextInt();
- searchBinary(n);
- }
- public static void searchBinary(int searchValue)
- {
- int a[] = {123,321,456,235,721,7420,69271,51,356,137,11,13,5,6,1};
- Arrays.sort(a);
- System.out.println("The sorted Array is: ");
- for(i=0; i<a.length; i++)
- {
- System.out.println(a[i]);
- }
- int returnValue = Arrays.binarySearch(a, searchValue);
- System.out.println("The index of the element is : " + returnValue);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment