编辑代码

class Main {
	public static void main(String[] args) {
           int[] sortedArray = {6, 17, 25, 34, 52, 63, 85};
        int targetElement = 6;

        // 调用二分查找算法
        boolean result = binarySearch(sortedArray, targetElement);

        if (result) {
            System.out.println("元素 " + targetElement + " 存在于数组中。");
        } else {
            System.out.println("元素 " + targetElement + " 不存在于数组中。");
        }
	}

    // 二分查找算法
    static boolean binarySearch(int[] arr, int key) {
        int low = 0;
        int high = arr.length - 1;

        while (low <= high) {
            int mid = (low + high) / 2;

            if (arr[mid] == key) {
                return true; // 找到了元素,返回true
            } else if (arr[mid] < key) {
                low = mid + 1;
            } else {
                high = mid - 1;
            }
        }

        return false; // 没有找到元素,返回false
    }

   


}