面试题:比较两个数字大小

面试题:有两个变量a和b,不用"if","?","switch"或其他判断语句,找出两个数中间比较大的。

利用绝对值来找到最大值。

int max = ((a + b) + Math.abs(a - b)) /2;

private int CompareInt(int a,int b) {
    int c = (a+b + Math.abs(a - b)) /2;
    return c;
}
原文地址:https://www.cnblogs.com/tianyaxue/p/3143432.html