Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding the middle number of three random numbers using only max and min functions in JAVA [closed]

Tags:

java

max

min

I've solved the problem, but I'm wondering if there is a faster way.

Assuming a, b, c are randomly generated numbers, is there a way to find the middle number by only using 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))));

Thanks a lot, any response would be greatly appreciated!

like image 646
IKillR Avatar asked Oct 21 '22 17:10

IKillR


1 Answers

what about the following?

min(min(max(a,b), max(b,c)), max(a,c))
like image 170
drone.ah Avatar answered Oct 24 '22 10:10

drone.ah