java 编写程序,从键盘输入10个整数,并存放到一个数组中,然后计算所有元素的和、最大值、最小值及平均值
时间: 2024-05-12 16:19:03 浏览: 125
```
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int[] arr = new int[10];
int sum = 0;
int max = Integer.MIN_VALUE;
int min = Integer.MAX_VALUE;
for (int i = 0; i < arr.length; i++) {
System.out.print("请输入第" + (i+1) + "个整数:");
arr[i] = input.nextInt();
sum += arr[i];
max = Math.max(max, arr[i]);
min = Math.min(min, arr[i]);
}
double avg = (double) sum / arr.length;
System.out.println("所有元素的和为:" + sum);
System.out.println("最大值为:" + max);
System.out.println("最小值为:" + min);
System.out.println("平均值为:" + avg);
}
}
```
阅读全文