not correct (Question: order don't know and searching in binary search)

PHOTO EMBED

Sat Aug 12 2023 19:55:23 GMT+0000 (Coordinated Universal Time)

Saved by @amisha2005nath #java

class binarySearch{
    public static void main(String[] arg)
    {
        int n=10;
        int arr[]={1,2,3,4,5,6,7,8,9,10};
        int key=8;
        int start=0;
        int end=n-1;
        int mid;
        if(arr[0]>arr[1])
        {
            System.out.println("Descending ");
            while(start<end)
            {
                mid=(start+end)/2;
                if(arr[mid]==key)
                {
                    System.out.println(/*"Element is " + key*/ " which present at index " + mid );
                    break;
                }
                else if(arr[mid]<key)
                {
                    start=mid+1;
                }
                else if(arr[mid]>key)
                {
                    end=mid-1;
                }
            }
        }
        else if(arr[0]<arr[1])
        {
            System.out.println("Ascending");
              while(start<end)
            {
                mid=(start+end)/2;
                if(arr[mid]==key)
                {
                    System.out.println(/*"Element is " + key*/ " which present at index " + mid );
                    break;
                }
                else if(arr[mid]>key)
                {
                    start=mid+1;
                }
                else if(arr[mid]<key)
                {
                    end=mid-1;
                }
            }
        }
        
    }
}
content_copyCOPY