二分法判断数据是否存在于指定数组中

int[] scores = {1, 23, 3, 40, 20};
Arrays.sort(scores);//对数组进行排序
int i = Arrays.binarySearch(scores, 4);
if (i >= 0)
System.out.println("数据在数组中存在");
else
System.out.println("数据在数组中不存在");
posted @ 2020-11-13 14:26  懂得归零  阅读(178)  评论(0)    收藏  举报