![]() |
To an array of integers with random values the nextInt() method from the java.util.Random class is used. From the random number generator sequence, this method returns the next random integer value. Assign a Random Value to an ArrayWe can assign random values to an array by two approaches. If we do not pass any arguments to the nextInt() method, then it will assign some arbitrary random value of integers range in Java and if we pass some argument to the nextInt() method then it will generate numbers in the range between 0 to the argument passed. Example 1:In this, we assign random values to an array without any range or ranging between the minimum value of integers to the maximum value of integers (i.e. not passing arguments). Java
Output
Random assigned value of Array are: -170019732 2032213863 -1596767761 -1668938134 -210148393 Example 2: In this, we are assigning random values to array with some specific range (i.e. passing arguments) Java
Output
Random assigned value of Array are: 4 51 85 25 33 |
Reffered: https://www.geeksforgeeks.org
Java |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 11 |