可以使用set集合对数组进行去重,再遍历判断是否存在0即可。示例代码如下:
int[] arr = {1, 2, 3, 0, 4, 5, 6, 0};
Set set = new HashSet<>();
for(int i = 0; i < arr.length; i++){
set.add(arr[i]); // 将数组元素添加到set集合中
}
if(set.contains(0)){
System.out.println("数组中包含0");
} else {
System.out.println("数组中不包含0");
}
if(set.size() == arr.length){
System.out.println("数组中没有重复数字");
} else {
System.out.println("数组中有重复数字");
}