Question

In: Computer Science

Document the arrays, using a chart with columns titled: outer loop, inner loop, i, j, and...

Document the arrays, using a chart with columns titled: outer loop, inner loop, i, j, and x. Finally, draw a picture of each array (after the program portion has executed). (5 pts) int[][] arr1 = new int[5][5]; int[][] arr2 = new int[5][5]; x = 1; for(int i = 0; I < 5; i++) { for(int j = 1; j < 6; j++) { arr1[i][j-1] = x; x++; if(x == 6) x += 2; } } for(int i = 4; i >= 0; i--) for(int j = 4; j > -1; j--) arr2[j][i] = arr1[i][j];

Solutions

Expert Solution

The answer is given in a tabular form :

Please note that in the first loop when i=0 and j=5, X has the value 5. Next time when the loop is executed, arr1[0][4] will be 5.

X gets incremented to 6. Now the if condition X==6 will be true . Hence x will get the value 8 after doing X+=2. Thats how arr1[1][0] has 8 in it. Hope this helps.


Related Solutions

Implement a version with the outer loop, with a while loop, and the inner loop with...
Implement a version with the outer loop, with a while loop, and the inner loop with a do / while loop. Modify this program as he ask ↑↑↑ C++ // This program averages test scores. It asks the user for the 2 // number of students and the number of test scores per student. 3 #include <iostream> 4 #include <iomanip> 5 using namespace std; 6 7 int main() 8 { 9 int numStudents, // Number of students 10 numTests; //...
Create a PL/SQL anonymous block that uses a nested loop (inner loop 1 to 15; outer...
Create a PL/SQL anonymous block that uses a nested loop (inner loop 1 to 15; outer loop 1 to 5) to perform computations using the SQL functions, ABS, EXP, SQRT, ROUND, MIN, MAX, LOG, MOD, REMAINDER and POWER The outer loop will use the functions, ABS, EXP, SQRT, ROUND to display the following messages (must be “ The absolute value of <outer loop index> is <value>” “ The value of e to the <outer loop index> power is <value>” “...
write a program bus management system? using: if else, for loop, do while loop, function, arrays,...
write a program bus management system? using: if else, for loop, do while loop, function, arrays, string, structure
I'm trying to get the union of two arrays and I tried making a loop that...
I'm trying to get the union of two arrays and I tried making a loop that does so. I tried also making the loop give me the size of the array as well from the union of the two arrays. Please check my loop to see what is wrong with it because it is not doing what I want it to do. I'm also not sure how to get the correct size of the array after the two arrays have...
Draw diagrams to show how to measure a)outer diameter, b)inner diameter, c)depth using a Vernier Calliper.
Draw diagrams to show how to measure a)outer diameter, b)inner diameter, c)depth using a Vernier Calliper.
I want to convert those codes to assembler code // Problem 1 // for loop J=5...
I want to convert those codes to assembler code // Problem 1 // for loop J=5 for(i=1; i<5; i++) {         j-- } // Problem 2 // if - then - else i=4 if (i < 5) then         j = 3 else         j = 2 // Problem 3 //while loop i = 0 j = 0 while(i==0) {   j++   if j = 5 then         i = j }
Write using C++ a) Inputs two 1D arrays of doubles A[i] and B[i] from the keyboard...
Write using C++ a) Inputs two 1D arrays of doubles A[i] and B[i] from the keyboard with a maximum size of 1000. The elements are input one at time alternating between A and B (ie A[0],B[0],A[1],B[1], …, A[i],B[i]) until a value of less than -1.0e6 is input or i >= 1000. Then the program continues to part b). b) Calculates C = A + B, where + is vector addition (ie C[i] = A[i] + B[i]), and prints each element...
We are to make a program about a car dealership using arrays. I got the code...
We are to make a program about a car dealership using arrays. I got the code to display all cars in a list, so I'm good with that. What I'm stuck at is how to make it so when a user inputs x for search, it allows them to search the vehicle. We need two classes, one that shows the car information and another that shows the insert, search, delete, display methods. Here is what I have so far package...
JAVA I need to write a code that calculates mean and standard deviation using arrays and...
JAVA I need to write a code that calculates mean and standard deviation using arrays and OOP. This is what I have so far. I'm close but my deviation calculator method is throwing errors. Thanks so much :) import java.util.Scanner; import java.util.Arrays; public class STDMeanArray { private double[] tenUserNums = new double[10];//Initialize an array with ten index' private double mean; private double deviation; Scanner input = new Scanner(System.in);//create new scanner object /*//constructor public STDMeanArray(double tenUserNum [], double mean, double deviation){...
I have created a MinHeap program without using arrays. Below is the followup question : The...
I have created a MinHeap program without using arrays. Below is the followup question : The heap class is a collection. Determine the correct location in your language’s collection class hierarchy. Find all methods that you need to implement in order to add your class in the language’s collection class hierarchy. What does this mean and how to implement it?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT