Here is how I read your if condition:
if ( ( (any time x is part of a pair) AND ( y is part of a pair that doesn't include x)) OR (z is not the same as k) )
Let's see how that would evaluate an example that should fail:
What I would do is break down problem into discreet steps. The first thing you need to know is that, with 4 elements, in order to get two pairs, X must be in a pair with one other element:
(x is the same as y) OR (x is the same as z) OR (x is the same as k)
Given that, in order to have two pairs, there is a requirement on the only two remaining elements left - they must be equal as well, so there is a remaining condition that must be met:
((x is the same as y) WHAT (z is the same as k)) OR ((x is the same as z) WHAT (y is the same at k)) OR ((x is the same as k) WHAT (y is the same as z))
Your mission is to determing the
word that should be used insted of WHAT, and then to translate that to
JAVA.