java判読配列に重複値があるかどうかの例
768 ワード
ここでは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(" !!!");
}
}