Finding the average of three random numbers using only max and min functions in JAVA

I solved the problem, but I wonder if there is a faster way.

Assuming a, b, c are randomly generated numbers, is there a way to find the average using only the Math.max and Math.min functions?

  med = Math.max(Math.max(Math.min(a,b),Math.min(b,c)),(Math.max(Math.min(b,c),Math.min(a,c))));

Thank you very much, any answer would be greatly appreciated!

+5
source share
1 answer

what about the next one?

min(min(max(a,b), max(b,c)), max(a,c))
+3
source

All Articles