java中通过索引求数组中的最值
/**
*
*Title: project_name
*Description:通过索引比较获取数组中的最值
*Makedate:2016年5月1日 下午1:33:50
*@author: sunt Email:wnst1990@126.com
*@version: 1.0
*/
public class Demo2 {
public static void main(String[] args) {
int [] arr = {13,324,456,56,4324324,676,7,68,70,98,0,-4324,435,-54,2432};
int max = getMax(arr);
System.out.println("数组中的最大值 = " + max);
}
/**
*
* 描述 : <获取数组中的最值>. <br>
* <p>
*
* @return
*/
public static int getMax(int [] arr){
int index = 0;
for (int i = 0; i < arr.length; i++) {
if(arr[i] > arr[index]){
index = i;
}
}
return arr[index];
}
}