/*判断两个数组中有无相同的数字
* 若相同则它的value为1
* 不同则value为0
*/
import java.util.*;
public class FindDifferent {
public static void main(String[] args) {
HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
int[] scource1 = new int[]{10, 20, 30, 40, 60};
int[] scource2 = new int[]{20, 25, 37, 60, 70};
for(int i=0; i<scource1.length; i++) {
map.put(scource1[i],0);
}
for(int j=0; j<scource2.length; j++) {
if(map.containsKey(scource2[j])) {
map.remove(scource2[j]);
map.put(scource2[j],1);
}else{
map.put(scource2[j],0);
}
}
System.out.println(map.toString());
}
}
判断两个数组是否有相同的数
最新推荐文章于 2022-12-04 22:36:51 发布