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

The output below is generated by this program segment 10 10 11 13 16 20 21 23 26

ID: 3817572 • Letter: T

Question

The output below is generated by this program segment

                     10 10 11 13 16

            20 21 23 26 30

            35 37 40 44 49

            55 58 62 67 73

      int twoD[][] = new int[4][5];

      int i, j, k = 10;

      for(i = 0; i < 4; i++)

      for(j = 0; j < 5; j++) {

          twoD[i][j] = k;

          k += i + j;

      }

      for(i = 0; i < 4; i++) {

      for(j = 0; j < 5; j++)

        System.out.print(twoD[i][j] + " ");

      System.out.println();

      }

          Given this program segment and its output, list the values of the multi - dimensional array elements and their expressions that are shown. Use the array           values that were generated after the program segment was executed. If a value or expression is undefined ( out of bounds ) , indicate this as such.

          Enter your responses in the spaces provided.

          _____ (a)      twoD[3][1]

          _____ (b)      twoD[1][3]

          _____ (c)       twoD[2][2]

          _____ (d)      twoD[0][4]

          _____ (e)      twoD[2][1] - twoD[1][2]

          _____ (f)       twoD[1][3] - twoD[1][2]

          _____ (g)      twoD[3][4] + twoD[4][3] - twoD[3][0]

          _____ (h)      twoD[2][3] + twoD[1][3] * twoD[2][1]

          _____ (i)       twoD[3][4] * 3

          _____ (j)       twoD[4][3] * 2

Explanation / Answer

since array indexing starts with a zero,twoD[i][j] will correspond to (j+1)th element of(i+1)th array
(a) 58 (row 4 column 2)
(b) 26 (row 2 column 4)
(c) 40 (row 3 column 3)
(d) 16 (row 1 column 5)
(e) 14 (37-23)
(f) 3 (26-23)
(g) undefined (twoD[4][3] doesnt exist, it will show some garbage value)
(h) 1006(44+(26*37)) =44+962=1006
(i) 219 (73*3)
(j) undefined (twoD[4][3] doesnt exist, it will show some garbage value)

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