62,614
社区成员
发帖
与我相关
我的任务
分享
public static void main(String[] args) {
int a[] = { 2, 1, 1, 4, 1, 3, 2, 2, 2, 3 };
int temp = -33333;
for (int i = 0; i < a.length; i++) {
if (i + 1 == a.length)
break;
if (a[i] == a[i + 1]) {
if (temp == a[i]) {
continue;
} else {
temp = a[i];
System.out.print(a[i] + " ");
}
}
}
}
int a[] ={2,1,1,4,1,3,2,2,2,3};
for(int i = 1;i<a.length;i++){
if(a[i-1]==a[i]){
System.out.println(a[i]);
}
}
不过中间的2输出两次