找出数组中的最大值

package chapter7;

/*
* 找出数组中的最大值
*/
public class TestArrayMax {
public static void main(String[] args) {
// 定义一个数组
int[] a = { 1, 9, 5, 4, 3, 0, 2 };
// 定义一个int类型的变量的数组并赋值0;
int max = a[0];
// for循环遍历数组,判断数组长度
for (int i = 0; i < a.length; i++) {
// 定义一个if条件判断定义的数组
if (max < a[i]) {
max = a[i];
System.out.println("max的值是:" + max);
}
}

}
}

-------------------打印-----------------------

max的值是:9

原文地址:https://www.cnblogs.com/Koma-vv/p/9539684.html