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