判读数组中是否有重复的值
此处使用int[]数组示范。。。。
public static void main(String[] args) {
int[] arry={1,10,5,8,11,100,99,10};
//用于判断是否有重复值的标记
boolean flag=false;
for (int i = 0; i < arry.length; i++) {
int temp=arry[i];
int count=0;
for (int j = 0; j < arry.length; j++) {
int temp2=arry[j];
//有重复值就count+1
if(temp==temp2){
count++;
}
}
//由于中间又一次会跟自己本身比较所有这里要判断count>=2
if(count>=2){
flag=true;
}
}
if(flag){
System.out.println("有重复值存在!!!");
}else{
System.out.println("没有重复值存在!!!");
}
}
复制代码
本文介绍了一种方法来判断给定的整数数组中是否包含重复元素,并通过实例演示了实现过程。
2万+

被折叠的 条评论
为什么被折叠?



