I don't get the point of this question. Java is pass by value, if they want the function signature to stay the same (i.e. not changing the type of the input parameters to for example AtomicInt or an array or ...), there's no solution for it in java. Can someone please either explain or share a link with some explanation of what they really want?
If a is a greater distance from x than b is from y, then the else conditions will trigger(thereby making b less than y even though it was greater at one point. They should be else if (a less than x) and else if (b less than y). And the && in the while loop should be ||. Otherwise once b reaches y, the while loop will break.
Either I didn't understand the question or you. I'm not talking about fixing the conditions (that's very easy and clear). I'm saying after fixing the conditions, at the end, a will be equal to X and b will be equal to Y LOCALLY. When the function returns, a and b still have their old values, because java is always pass-by-value. The question is saying find the bug to make a equal to X and b equal to Y. Once the function returns a and b still have their old values.
The premise of the question is indeed idiotic lol because of pass-by-value. But yes, the best you can do is fix the conditions.
Do you mind sharing the question too, in addition to your critique?
Just Google "Microsoft OTS makeNumbersMatch"
Can't find it