Implement a method with the signature public static int bin

Implement a method with the signature:

public static > int binarySearch(AnyType[] a, AnyType x);

This method should then search the array recursively for the value x.

Solution

import java.util.Arrays;

public class ArrayDemo {

   public static void main(String[] args) {

   // initializing unsorted int array

   int intArr[] = {30,20,5,12,55};

   // sorting array

   Arrays.sort(intArr);

   // let us print all the elements available in list

   System.out.println(\"The sorted int array is:\");

   for (int number : intArr) {

   System.out.println(\"Number = \" + number);

   }

   // entering the value to be searched

   int searchVal = 12;

   int retVal = Arrays.binarySearch(intArr,searchVal);

               

   System.out.println(\"The index of element 12 is : \" + retVal);

   }

}

Implement a method with the signature: public static > int binarySearch(AnyType[] a, AnyType x); This method should then search the array recursively for the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site