package com.lovcoding.day06;

import java.util.Scanner;

public class TestArr02_Search02 {

    //查找多个最大值
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入查找的值");
        int target = scanner.nextInt();

        int[] arr = {1,3,5,6,8,9,11,14,16,18,19,22,25,27,28,29,35,46,57,67,78,98};
        //mid left right
        int left = 0;
        int right = arr.length-1;

        while (true){
            int mid = (left + right) /2;
            //比较
            if ( arr[mid] > target  ){
                right = mid - 1;
            }else if (arr[mid] < target){
                left = mid+1;
            }else{
                System.out.println("索引="+mid);
                break;
            }
        }

    }
}
