Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Hostgator 1 Penny

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Distribute your Resume to 500+ Job Boards & Recruiters


7,621 questions

10,674 answers

573 users

How to fill an array with random numbers in Java

1 Answer

0 votes
import java.util.Random;

public class MyClass {

    public static void main(String args[]) {
         
        int[] arr = new int[15];
        
        Random randomGenerator = new Random();
        for (int i = 0; i < arr.length; i++) 
            arr[i] = randomGenerator.nextInt(500) + 1;

        for(int i:arr) 
            System.out.print(i + " ");
    }
}

/*
 
run:
 
132 163 185 246 326 120 304 25 417 479 306 449 41 467 302 
 
*/

 




answered May 13 by avibootz
...