Java基础 求数组最大值最小值
代码示例如下:
package com.itheima.Text1;
public class Text002 {//求数组中最大值代码示例
public static void main(String[] args) {
int[] arr = {12, 14, 15, 16, 71};
int max = arr[0];
for (int i = 1; i < arr.length; i++)
if (arr[i] > max) {
max = arr[i];
}
/**最小值代码如下
int min = arr[0];
for (int i = 1; i < arr.length; i++)
if (arr[i] < min) {
min = arr[i];
}
System.out.println("min:" + min);
**/
System.out.println("max:" + max);
}
}