<<
Math.min(a, Math.min(b,c));
>>
<<
import org.apache.commons.lang.math.NumberUtils;NumberUtils.min(a,b,c);
NumberUtils.min(new int[]{a,b,c});
>>

解决方案 »

  1.   

    public static int min(int a, int b, int c) {
    return (a > b ? b : a) > c ? c : (a > b ? b : a);
    }
      

  2.   

    liumt88:你是garbage
    xiaohaiZ:同意应该尽量使用类库中的方法,但是如果要在4个数中求最小值你怎办?你写个出来瞧一瞧
    kenny1979:不是算法问题
    cold_blooded:只有你自已看得懂,0分
      

  3.   

    靠,好心帮你顶,怕你沉,你尽说我是garbage
      

  4.   

    但是如果要在4个数中求最小值你怎办?你写个出来瞧一瞧
    @see NumberUtils#min(int[])
      

  5.   

    呵呵,大家都别激动嘛。其实xiaohaiz说得很对啊,这个类库不仅仅限于Java的标准类库。
    cold_blooded的方法虽然你看不懂,不代表只有他自己看得懂三,对不?有兴趣的话看看org.apache.commons.lang.math.NumberUtils是怎么做的吧。
      

  6.   

    // Min in array
        //--------------------------------------------------------------------
        /**
         * <p>Returns the minimum value in an array.</p>
         * 
         * @param array  an array, must not be null or empty
         * @return the minimum value in the array
         * @throws IllegalArgumentException if <code>array</code> is <code>null</code>
         * @throws IllegalArgumentException if <code>array</code> is empty
         */
        public static long min(long[] array) {
            // Validates input
            if (array == null) {
                throw new IllegalArgumentException("The Array must not be null");
            } else if (array.length == 0) {
                throw new IllegalArgumentException("Array cannot be empty.");
            }
        
            // Finds and returns min
            long min = array[0];
            for (int i = 1; i < array.length; i++) {
                if (array[i] < min) {
                    min = array[i];
                }
            }
        
            return min;
        }这个是org.apache.commons.lang.math.NumberUtils源码哈。
    // developed by the Apache Software Foundation (http://www.apache.org/).
      

  7.   

    TO sean_gao:俺也想回“......”的,被你抢先了。
    另外,被别人爱也是好事哦。^^