1. public static void main(String[] args) {
    2. int[] a = {2,5,8,9,4,2,3,10,20} ;
    3. int max = a[0];
    4. for (int i = 1; i < a.length; i++) {
    5. //如果当前元素比max大,则max为当前元素
    6. if (a[i] > max) {
    7. max = a[i];
    8. }
    9. }
    10. System.out.println("最大值:" + max);
    11. }