Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem Description ASU Home My ASU Colleges For this lab, you will create a 2D Array where you will be storing values of type integer,

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Problem Description ASU Home My ASU Colleges For this lab, you will create a 2D Array where you will be storing values of type integer, fill in the elements of that array by prompting the user for input then display the elements of the array. Then you will need to find the sum of each row of array and display it. Step 1: Getting Started Create a new .java file named Lab11.java. Import the following libraries: java.util.Scanner; java.util.Arrays; Lab11 is the name of the class that contains the main function. public class Lab11 { public static void main(String[] args) { Step 2: Declaring Variables For this section of the lab, you will need to declare four local variables: one Scanner to read input from the user, one integer for the number of rows, one integer for the number of columns, and one integer that will be used to sum of the elements of each row. Declare these variables inside of your main method. // A scanner object for requesting input from the user // --> // An integer for the number of rows. // --> // An integer for the number of columns. // --> // an integer for sum of each row's elements //--> Step 3: Request Array Size from the User ASU Home My ASU Colleg Next, use the Scanner object declared in the previous step to request from the user the number of rows and columns which are needed to declare your 2D array. Prompt the user to enter these numbers. // Print this message "Enter the number of rows in the array" // --> // Print this message "Enter the number of columns in the array // --> // Use the scanner to store the values entered by the user // in the integers declared above. // --> Step 4: Declare the Array Next, declare a 2D array with the requested number of rows and columns. // Declare a 2D integer array with the number of rows and columns requested by the user // --> // Remember, we declare a 2D integer array by using a statement like: // int[][] intArray = new int[NumberOfRows] [NumberOfColumns]; Step 5: Fill in the Array ASU Home My ASU Colleges Using a nested for loop structure, we will walk through the 2D array with one (outer) loop for the rows and one (inner) loop for the columns. For each iteration of the inner loop, ask the user for a value and store that value i the correct element element of the array. for (int rowIndex = 0; rowIndex // Store the value entered by the user at the (ith, jth) position of the 2D array created in Step 4. // --> Step 6: Display the Array's Elements ASU Home My ASU Colleges Again using a similar nested loop structure, we will now display the values of the elements of the array back to the user. The values should all be printed with a space between each value and a new Line after each row. for (int rowIndex = 0; rowIndex printed the value at this row, column in the array Remember the outer loop walks through the rows, while the inner loop walks through the elements of the rows. Step 7: finding sum of each row and display Now we would like to find the sum of each row of values and display it. We need to use a nested loop structure and sum variable. Before starting the second loop you need to make the sum equal to zero. // the first loop for (int rowIndex = 0; rowIndex

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine M. Ricardo, Susan D. Urban, Karen C. Davis

4th Edition

1284231585, 978-1284231588

More Books

Students also viewed these Databases questions

Question

Discuss the difference between base pay and pay-for-performance.

Answered: 1 week ago

Question

=+can you write alternative statements that are better?

Answered: 1 week ago