Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

CS 1113 LAB Twe Dimensional Arrwys Lab Goals OTo teach you how to and index 2-di

ID: 3808910 • Letter: C

Question

CS 1113 LAB Twe Dimensional Arrwys Lab Goals OTo teach you how to and index 2-dimensional amays 20 To show you how to iterate over two dimensional armys with nested loops Amays are a powerful data structure, but sometimes we want to store a table of data, motjustalinear list. That is where 2 dimensional arrays come in. In Java, to make a 2 dimensional array, we make an array ofamays. This is easy because an array is just a special kind of object in Java. Common uses of2D amays include digital images (2D ofoolor values, grades for students in different assignments and stock quotes for multiple stocks over time. Declaring 2D arrays In Java, to make a 2D amay, we simply declare an array where the type isan array To see how this works, first look at how we create an int array with 10 elements. One might type int arrID new int [101 What the above code actually doesiscreate a new object of type "int reserves enough space to store intepers. Since an int array (written in(D isjust of object we can make an array of them, by appending another set of square brackets: arr2D new int13 This declares a two dimensional array of ints with 3 rows and 7columns. By convention, think of the amay as being indexed in which means that the row value) comes before the column (x Thus, visually, the array looks like this: 0 0 0 0 0 0 0 The is position and bomom right element is at position1216) The amay elements are initialized just the set to 0, and object types are set to null). as in the ID case (numerics are wrie the answers to the numbered questions in a sle called absanswers tot write your name at the top ofthis Q1) What code would you use to create a 2D array of double with 4 ows and 9 columns? To access one ofthe clements of 2D array, we use double bracket notation again, so we can write ar 20 ar 20121 13

Explanation / Answer

HI, Friend, Images are not clearly redable.

I have answered first three questions.

Please repost clearly visible images or codes.

Q1.
   int[][] array2D = new int[4][9];

Q2.
   100 100 100 100 100 100 100 100 100
   100 100 100 100 100 100 100 100 100
   100 100 100 100 100 100 100 100 100
   100 100 100 100 100 100 100 100 100

Q3.
   Code to add all elements of array2D

   int sum = 0;
   for(int r =0; r<array2D.length; i++){

       for(int c=0; c<array2D[r].length; c++){

           sum = sum + array2D[r][c];
       }
   }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote