解题:
import java.util.Random;
import java.util.Scanner;
public class LianXi01 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入数组长度:");
int length = sc.nextInt();
int a[] = new int[length];
System.out.println("数组长度为:" + length);
System.out.println("==================");
Random ran = new Random();
int sum = 0;
System.out.print("数组为:[");
for (int i = 0; i < length; i++) {
int num = ran.nextInt(100) + 1;
a = num;
sum += a;
if (i < length-1){
System.out.print(num + ",");
}else {
System.out.println(num + "]");
}
}
System.out.println("数组的和值为:"+sum);
System.out.println("==================");
int temp = a[0];
int max = temp;
for (int j = 1; j < length; j++) {
max = (max > a[j] ? max : a[j]);
}
System.out.println("数组最大值为:" + max);
System.out.println("==================");
double avr = (double) sum / (double) length;
System.out.println("平均值为:"+avr);