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);
}
}
複製代碼