**
数组 10 随机赋值 两位数 求最大值 最小值 求和 平均数
**
package com.hy.exer;
/**
*
- @Description 数组 10 随机赋值 两位数 求最大值 最小值 求和 平均数
- @author lph Email:liupenghao1201@163.com
- @version
- @date 2022年5月18日上午11:03:03
*/
public class ArrayExet {
public static void main(String[] ages) {
// 初始话数组
int[] shuzu = new int[10];
// 随机赋值
for (int i = 0; i < shuzu.length; i++) {
shuzu[i] = (int) (Math.random() * (99 - 10 + 1) + 10);
System.out.print(shuzu[i] + " ");
}
System.out.println();
// 求最大值
int max = shuzu[0];
for (int i = 0; i < shuzu.length; i++) {
if (max < shuzu[i]) {
max = shuzu[i];
}
}
System.out.println("最大值为:" + max);
// 求最小值
int min = shuzu[0];
for (int i = 0; i < shuzu.length; i++) {
if (min > shuzu[i]) {
min = shuzu[i];
}
}
System.out.println("最小值为:" + min);
// 求和
int sum = 0;
for (int i = 0; i < shuzu.length; i++) {
sum += shuzu[i];
}
System.out.println(" 和为:" + sum);
// 求平均数
float ar = 0;
ar = ((float) sum / (float) shuzu.length);
System.out.println("平均数为 :" + ar);
}
}


该篇博客展示了如何使用Java编程随机生成一个包含10个两位数的数组,并进行最大值、最小值、求和及平均数的计算。通过循环遍历和条件判断,实现数值的比较和统计操作,为初学者提供了一个简单的算法实践示例。
5128

被折叠的 条评论
为什么被折叠?



