我有两个数组, 想拿出两个数组中不同的数字
- 摘要:我有两个数组,{1,3,2,5,6,8},{7,4,9,1,5}想取出这两个数组中不同的数字,String[]s1={"1","3","2","5","6","8"};String[]s2={"7","4","9","1","5"};for(inti=0;i<s1.length;i++){for(intj=0;j<s2.length;j++){if(s1[i]!=s2[j]){System.out.println(s1[i]);}}}上面是我写的
- 标签:数组
我有两个数组,{1,3,2,5,6,8},{7,4,9,1,5}
想取出这两个数组中不同的数字,
String []s1= { "1","3","2","5","6","8"};
String []s2= {"7","4","9","1","5"};
for(int i=0;i<s1.length;i++){
for (int j = 0; j < s2.length; j++) {
if(s1[i] != s2[j]){
System.out.println(s1[i]);
}
}
}
上面是我写的, 运行后显示不一样的数字每个都显示了5遍, 能不能只显示一遍?