从10号阵列生成1000个随机数,找到数字的平均值并在屏幕上打印出来

时间:2016-12-06 14:39:52

标签: java

var root = JsonConvert.DeserializeObject<RootObject>(jsonString); 
var events = root.events;

我根本无法生成随机数。如何从10号阵列生成1000个随机数并找到数字的平均值并将其打印在屏幕上?

2 个答案:

答案 0 :(得分:0)

试试这个:

    import java.util.Random;
    public class exam1
    {
    public static void main (String args[])
    {
    //  Scanner scan = new    Scanner(System.in);
        int array [] = new int[10];
        Random rand = new Random();
        //You could use just one variable
        int sum = 0;

        for(int i=0; i<array.length; i++)
        {
    //Generate random integer between 0 and 1000
            array[i]=rand.next(1000);
            sum = sum+array[i];
            sum=sum/array.length;
        }
            System.out.println(sum);
    }

}

答案 1 :(得分:0)

SSH_PRIVATE_KEY

我认为这是有效的