1 public class gkhkhh { 2 3 public static void main(String[] args) { 4 // TODO Auto-generated method stub 5 6 7 int arr []=new int[]{ 12,34,22,11,8,9,4}; 8 9 for (int a=0;a<7;a++) 10 { 11 System.out.print(arr[a]+" "); 12 } 13 14 15 16 int arr1 []=new int[]{ 12,34,22,11,8,9,4};//创建数组初始数据 17 18 for ( int b= 0; b< 7;b++ ) 19 { 20 System.out.println(arr[b]); // 输出数组数据 21 22 } 23 int max=arr[0]; 24 25 for ( int k= 0; k<6;k++) //通过for循环遍历数组 26 27 { 28 if ( max< arr[k +1]) //判断大小的条件 29 30 { 31 max =arr [k+1]; 32 33 } 34 } 35 System.out.println("arr[0]中最大值:"+max); 36 } 37 38 }
12 34 22 11 8 9 4 12
34
22
11
8
9
4
arr[0]中最大值:34