Just convert this array into a Map<Integer, Integer>
and then print it out, like this:
public static void main(String[] args) throws Exception {
final int[][] dataTable = new int[][] {
new int[] {0, 1, 2, 1},
new int[] {0, 1, 3, 1},
new int[] {0, 1, 2, 2},
new int[] {0, 1, 2, 0}
};
final Map<Integer, Integer> map = new HashMap<Integer, Integer> ();
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
final int value = dataTable[i][j];
final Integer currentCount = map.get(value);
final Integer newCount;
if (currentCount == null) {
newCount = 1;
}
else {
newCount = currentCount + 1;
}
map.put (value, newCount);
}
}
for (final Map.Entry<Integer, Integer> entry : map.entrySet()) {
System.out.println(String.format ("The number %d repeats %d times", entry.getKey(), entry.getValue()));
}
}
Here you can find the results.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…