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

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){...
Write a for loop from 1 to 3 using i as the variable. For each value...
Write a for loop from 1 to 3 using i as the variable. For each value of i: Create a vector x of 10 random numbers between 0 and 1. Create a second vector t which is equal to ten integers from 1 to 10. Plot x versus t in figure 1. Use hold on to keep each plot. Use a different color for the line for each value of i. At the very end, add the text 'time' using...
I want to compare a string with the previous strings in a forEach loop using javascript....
I want to compare a string with the previous strings in a forEach loop using javascript. So im accessing data from an API. Im iterating through them using a forEach() loop. I want to compare the current 'title' string from the api with all previous title strings its pulled. The title is located under article.title fetch(req)             .then((response) => {                 return response.json();             })             .then((data) => {                 console.log(data);                 data.articles.forEach((article) => { } If the title matches any other title used already id...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT