public static void main(String args[]) { //随机10个数赋值到数组内 int[] ars = new int[10]; int max = ars[0]; int min = ars[0]; int count = 0; for(int i = 0;i < ars.length;i++) { ars[i] = (int)(Math.random()*(99 - 10 + 1)); if(ars[i] > max) { max = ars[i]; } if(ars[i] < min) { min = ars[i]; } count = count + ars[i]; } //平均值 int avg = count / ars.length; System.out.println(avg); //数组的最大值 System.out.println(max); //数组的最小值 System.out.println(min); //数组的数字和 System.out.println(count);
public static void main(String args[])
{
//随机10个数赋值到数组内
int[] ars = new int[10];
int max = ars[0];
int min = ars[0];
int count = 0;
for(int i = 0;i < ars.length;i++)
{
ars[i] = (int)(Math.random()*(99 - 10 + 1));
if(ars[i] > max)
{
max = ars[i];
}
if(ars[i] < min)
{
min = ars[i];
}
count = count + ars[i];
}
//平均值
int avg = count / ars.length;
System.out.println(avg);
//数组的最大值
System.out.println(max);
//数组的最小值
System.out.println(min);
//数组的数字和
System.out.println(count);
JAVA用数组和随机数实现求平均值,最大值,最小值------JAVA
于 2023-04-09 11:58:02 首次发布