展开全部
import java.util.Random;
public class Test{
/**
* 计算平均数
* @param numSize 随机的数字个数
* @param average 平均值
* @return 随机数数组
*/
public int[] test(int numSize,int average)
{
Random rand = new Random();
int result[] = new int[numSize];
if(numSize%2 ==0)
{
for(int i = 0;i
{
int rand1 = rand.nextInt();
int leave1 = average - rand1;
int leave2 = average + rand1;
result[i] = leave1;
result[i+1] = leave2;
}
}
else
{
for(int i = 0;i
{
int rand1 = rand.nextInt();
int leave1 = average - rand1;
int leave2 = average + rand1;
result[i] = leave1;
result[i+1] = leave2;
}
result[numSize-1] = average;
}
return result;
}
public static void main (String[] args){
int test[] = new Test().test(8, 16);
int total = 0;
for(int i =0;i
{
System.out.println("第"+(i+1)+"个数:"+test[i]);
total +=test[i];
}
System.out.println("总和e5a48de588b662616964757a686964616f31333335336433:"+total);
}
}