Answer:
- import java.util.Random;
- import java.util.Arrays;
- public class Main {
-
- public static void main(String[] args) {
- int n = 10;
- int [] myArray = new int[n];
- buildArray(myArray, n);
- System.out.println(Arrays.toString(myArray));
- }
-
- public static void buildArray(int[] arr, int n){
- for(int i=0; i < arr.length; i++){
- Random rand = new Random();
- arr[i] = rand.nextInt(90) +10;
- }
- }
- }
Step-by-step explanation:
Firstly, create a method buildArray that take two inputs, an array and an array size (Line 12). In the method, use random nextInt method to repeatedly generate a two digit random number within a for loop that will loop over array size number of times (Line 13-15). The expression rand.nextInt(90) + 10 will generate digits between 10 - 99.
In the main program, call the build array method by using an array and array size as input arguments (Line 8). At last, print the array after calling the buildArray method (Line 9).