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().

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Programming exercise  (in java eclipse, please add comments for each step). Write a complete Java program named FindProduct that contains the 
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" 

Expert Solution
Program Approach

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.
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

This question does not have an answer???

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education