Menu

[Solved]-Use Two Dimensional Array Store Table Values Element Array Accessed Two Indexes Firstone S Q37211413

We can use a two dimensional array to store a “table” of values.Each element in the array is accessed by TWO indexes – the firstone specifies the row, and the second one specifies the column.It’s pretty easy to simply declare a two dimensional array, sticksome values in there and then print them out. But some problemsrequire you to access the data in something other than the”normal” manner which (row by row, top to bottom) we’ve demonstratedin class. In this lab, you can practice working with 2D arrays bysimply printing out the elements of an array in a different sequencethan the “normal” way.Your assignment is to add to this program so that it willproduce the following output when it is executed. I’veincluded a few lines of code that will print out the FIRSTline of output. Use it as a starting point.NOTE: Do NOT change the values in the “ar” array!Name your source file “Lab8.java” and put it in the directory~/PF2/lab8== OUTPUT =================================================1 2 3 4 5 6 7 8 9 10 11 12 4 3 2 1 8 7 6 5 12 11 10 9 9 10 11 12 5 6 7 8 1 2 3 4 12 11 10 9 8 7 6 5 4 3 2 1 1 5 9 2 6 10 3 7 11 4 8 12 9 5 1 10 6 2 11 7 3 12 8 4 4 8 12 3 7 11 2 6 10 1 5 9 12 8 4 11 7 3 10 6 2 9 5 1 ===========================================================public class Lab8{ public static void main(String argv[]) { int ar[][] = new int[3][4]; int n = 1; for (int i=0; i < ar.length; i++) { for (int j=0; j< ar[i].length; j++) { ar[i][j] = n; n++; } } // print out the elements of the array // left to right, top to bottom for (int i=0; i < ar.length; i++) { for (int j=0; j < ar[i].length; j++) { System.out.print(ar[i][j] + ” “); } } System.out.println(); // your code goes here! }}

Expert Answer


Answer to We can use a two dimensional array to store a “table” of values. Each element in the array is accessed by TWO indexes -… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *