import java.util.function.IntFunction; class EqualPairCounter { int numberOfEqualPairsQuadratic(int[] arr) { int res = 0; for (int i = 1; i < arr.length; i++) { for (int j = i + 1; j < arr.length; j++) { if (i != j && arr[i] == arr[j]) { res++; } } } return res; } int[] arr = new int[] {2,3,5,7,3,9,6,5,6,6,2,4,1,6,3}; int pairCount = new EqualPairCounter().numberOfEqualPairsQuadratic(arr); } }