import java.util.*;
import java.lang.*;
import java.io.*;

class Main {
    int binarySearch(int arr[], int l, int r, int x)
    {
        if (r >= l) {
            int mid = l + (r - l) / 2;
            if (arr[mid] == x)
                return mid;
            if (arr[mid] > x)
                return binarySearch(arr, l, mid - 1, x);
            return binarySearch(arr, mid + 1, r, x);
        }
        return -1;
    }
    
    public static void main(String args[])
    {
        Main ob=new Main();
        Scanner b =new Scanner(System.in);
      
        System.out.println("Enter the number of Teams:");
        int n =b.nextInt();
        if(n==0||n<0)
        {
            System.out.println("Invalid Input");
        }
        else
        {
            int a[]=new int[100];
            System.out.println("Enter the score:");
            for(int i=0;i<n;i++)
            {
                a[i]=b.nextInt();
            }
            System.out.println("Enter the score to be searched:");
            int x=b.nextInt();
            if(x==0||x<0)
            {
                System.out.println("Invalid Input");
            }
            else
            {
                int result=ob.binarySearch(a,0,n-1,x);
                int r= result+1;
                if(result==-1) System.out.println("Score Not Found");
                else System.out.println(x+" is the score of Team "+r);
            }
        }
    }
 
    // Driver method to test above
    // public static void main(String args[])
    // {
    //     Main ob = new Main();
    //     int arr[] = { 2, 3, 4, 10, 40 };
    //     int n = arr.length;
    //     int x = 10;
    //     int result = ob.binarySearch(arr, 0, n - 1, x);
    //     if (result == -1)
    //         System.out.println("Element not present");
    //     else
    //         System.out.println("Element found at index " + result);
    // }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: