java求助,求解答

「已注销」 「已注销」 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
Arrays数组的二分搜索法 查数组的时候查不到int 类型的45 我的打印结果是-7

代码和图片会附上
public class ArraysDemo {
public static void main(String[] args) {
function1();
}
/*
* static int binarySearch(数组,被查找的元素)
* 数组的二分搜索法
* 返回元素在数组中出现的索引
* 元素不存在,返回的是-(插入点-1)
*/
public static void function1() {
int[] arr = {45,45,45,21,45,22,54};
int index = Arrays.binarySearch(arr,45);
System.out.println(index);

}
}
...全文
评论 2
收藏 已收藏
分享
返回顶部
「已注销」
Java SE 62,621 成员 307,251 内容