二分法判断数据是否存在于指定数组中
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("数据在数组中不存在");
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("数据在数组中不存在");