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
