java学习p163

import java.util.Scanner;
public class a1 {
    public static void main(String[] args) {
        Scanner myScanner = new Scanner(System.in);
        System.out.println("请输入数组的长度");
        int a = myScanner.nextInt();
        int[] arr = new int[a];
        System.out.println("请输入数组元素的值");
        for (int i = 0;i < arr.length;i++) {
            arr[i] = myScanner.nextInt();
        }
        int sum = 0;
        for (int i = 0;i < arr.length;i++) {
            sum += arr[i];
        }
        System.out.println("数组的和为 " + sum);
        System.out.println("数组的平均值为 " + sum / arr.length);
    }
}

你可能感兴趣的:(java,开发语言,后端)