Fastest way of finding the middle value of a triple?

前端 未结 25 877
庸人自扰
庸人自扰 2020-12-04 12:20

Given is an array of three numeric values and I\'d like to know the middle value of the three.

The question is, what is the fastest way of finding the midd

相关标签:
25条回答
  • 2020-12-04 13:03

    You can use array, like this:

    private static long median(Integer i1, Integer i2, Integer i3) {
    
        List<Integer> list = Arrays.asList(
                i1 == null ? 0 : i1,
                i2 == null ? 0 : i2,
                i3 == null ? 0 : i3);
    
        Collections.sort(list);
        return list.get(1);
    }
    
    0 讨论(0)
提交回复
热议问题