求出數組中重複 value 的個數

	public static void main(String[] args) {


		int[] arr = {1, 4, 1, 4, 2, 5, 4, 5, 8, 7, 8, 77, 88, 5, 4, 9, 6, 2, 4, 1, 5};
		int[] num = new int[124];
		for (int i = 0; i < arr.length; i++) {
			num[arr[i]]++;
		}
		for (int j = 0; j < num.length; j++) {
			if (num[j] != 0) {
				System.out.println(j + "出現了" + num[j] + "次");
			}
		}

	}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章