数组获取最大值:
class Hello2 { public static void main(String[] args) { int[] arr = {11,12,13,14,15}; int max = getMax(arr); System.out.println("max =" + max); } public static int getMax(int[] arr) { int max = arr[0]; for (int i = 1;i < arr.length ;i++ ) { if (max < arr[i]) { max = arr[i]; } } return max; } }
结果: