public class Hello {
public static void main(String[] args) {
int[] arr = { 1, 5, 2, 54, 3, 6, 4, 3 ,3,3};
int count = 1;
//先做排序
for (int i = 0; i < arr.length - 1; i++) {
for (int j = 0; j < arr.length - 1 - i; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
for (int i : arr) {
System.out.print(i+" ");
}
//循环比较
for (int i = 0; i < arr.length-1; i++) {
if(arr[i] == arr[i+1]) {
count++;
}
}
System.out.println();
System.out.println("count:"+count);
}
}
复制代码
转载于:https://juejin.im/post/5c0f7f9a51882505d84070a2