小编Ene*_*kan的帖子

如何将数组中的随机数分配给值?

我有一个数组的问题,并将它们分配给像float这样的值.这是我的代码

System.out.print("Please enter the number of iteration: ");
    Scanner scn = new Scanner(System.in);
    int inumber = scn.nextInt(); // i get the iteration number

        Random rnd = new Random();
        float x = -10 + rnd.nextFloat() * 20; // i created random number between 10 and -10
        System.out.println("My x = " +x);

            float[] xarray = new float[4]; // created my test array
            Random arrayrnd = new Random();


        for (int i=0;i<inumber;i++) { // created a for loop with that number

            for (int j …
Run Code Online (Sandbox Code Playgroud)

java arrays random loops

-3
推荐指数
1
解决办法
98
查看次数

标签 统计

arrays ×1

java ×1

loops ×1

random ×1