a. A main method asks the user to provide the number of rows and columns for a 2-dimensional array of integers. b. A main method calls the getArray() method that creates the 2D array of specified size and populates it with random values from 0 to 100. c. A main method prints the elements of the 2D array created by getArray().
following:
a. A main method asks the user to provide the number of rows and columns for a 2-dimensional array
of integers.
b. A main method calls the getArray() method that creates the 2D array of specified size and populates
it with random values from 0 to 100.
c. A main method prints the elements of the 2D array created by getArray().
d. A main method calls the printProduct method that will:
i. Receive the two-dimensional array as input
ii. Calculate the product of elements in each row of the array
iii. Display the product on the Console.
The product of all elements in each row should be formatted as "Row 1 Product XXXX"
The steps to create the program are mentioned below.
- Define the method getArray to populate the array with random numbers.
- Create an object of the random class.
- Use for loop to iterate through the rows and columns of the array.
- Generate a random number between 1 and 100 using rand_num.nextInt method and assign it to the array element.
- Defint the method printProduct to print the product of row elements.
- Iterate through each row of the array.
- Initialize prod to 1.
- Interate through each column of the array.
- Accumulate the product of each element in the prod variable.
- Print the computed product for the current row.
- In the main method, input the number of rows and number of columns for the array.
- Create the array with the number of rows and columns.
- Call the function getArray and printProduct.
Step by step
Solved in 4 steps with 3 images