4-9
package practice4_9; import java.util.Arrays; /* * 编写数组静态赋值 */ public class test01 { public static void main(String[] args) { int[] arr1 = {10,20,30,40,50}; System.out.println(Arrays.toString(arr1)); /* * 动态赋值 */ int[] arr2 = new int[5]; int a= 1; for (int i = 0; i < arr2.length; i++) { arr2[i]=a*10; System.out.println(arr2[i]); a++; } /* * 数组求和 平均值 */ int[] arr3= {23,45,22,33,56}; int sum=0; for (int i = 0; i < arr3.length; i++) { sum+=arr3[i]; } System.out.println(sum); int average = sum/arr3.length; System.out.println(average); /* * 最大值和下标记 */ int[] arr4 = {18,25,7,36,13,2,89,63}; int max = arr4[0]; int i; for ( i = 0; i < arr4.length; i++) { if (max<arr4[i]) { max=arr4[i]; } } System.out.println(max); for (int j = 0; j < arr4.length; j++) { if (max==arr4[j]) { System.out.println(j); } } } }