4.9w+
社区成员
package doit;
import java.util.HashSet;
import java.util.Set;
public class xxx {
public static void main(String[] args) {
int[] m = { 1, 3, 6, 5, 7, 1, 5, 6, 1, 6 };
test(m);
}
static void test(int [] m){
Set s = new HashSet();
for (int i = 0; i < m.length; i++) {
int count = 1;
for (int j = 0; j < m.length; j++) {
if (m[i] == m[j] && i!=j) {
count++;
s.add(i);
s.add(j);
}
}
if (count > 1) {
System.out.println("值:" + m[i] + "位置:" + s.toString());
s=new HashSet();
}
}
}
}
还是有问题,会重复输出package doit;
public class XXX {
public static void main(String[] args) {
int [] m = {1,3,5,6,7,1,5,6,1,6};
for (int i = 0; i < m.length; i++) {
boolean bo =false;
int a=0;
int b=0;
int c=0;
for (int j = 0; j < m.length ; j++) {
if(m[i]==m[j]){
if(i!=j){
bo=true;
a=i;
b=j;
break;
}
}
}
for (int k = b+1; k < m.length; k++) {
if(m[a]==m[k]){
bo=true;
c=k;
break;
}
}
if(bo){
if(c!=a && c!=b){
System.out.println("值:"+m[i]+"位置:"+a+","+b+","+c);
}
}
}
}
}
代码还存在漏洞,求指点