Finding the max/min value in an array of primitives using Java

前端 未结 15 2060
遥遥无期
遥遥无期 2020-11-22 05:09

It\'s trivial to write a function to determine the min/max value in an array, such as:

/**
 * 
 * @param chars
 * @return the max value in the array of chars         


        
15条回答
  •  遥遥无期
    2020-11-22 05:38

        public int getMin(int[] values){
            int ret = values[0];
            for(int i = 1; i < values.length; i++)
                ret = Math.min(ret,values[i]);
            return ret;
        }
    

提交回复
热议问题