IT 401 Assignment 4 Solution


Question One

a) Consider the following 2-dimensional array. Write a code snippet that gives the number of columns in the third row.

int[][] counts =

{

{ 0, 0, 1 },

{ 0, 1, 1, 2 },

{ 0, 0, 1, 4, 5 },

{ 0, 2 }

};

b) Write a code snippet, that defines a two-dimensional array of 200 rows and 100 columns of the type integer?

c) Consider the following code snippet:

int[][] arr =

{

{ 13, 23, 33 },

{ 14, 24, 34 }

};

Write the appropriate statement to display the value 24 from the given array?

d) Consider the following code snippet:

int[][] arr =

{

{ 11, 22, 33 },

{ 44, 55, 66 }

};

int val = arr[0][0] + arr[1][2];

System.out.println(val);

What is the output of the given code snippet on execution?

e) Consider we a have the following two dimensional array

{ 1, 2, 3, 0 }

{ 4, 5, 6, 0 }

{ 0, 0, 0, 0 }

Write a code snippet to print the sum of the highlighted color numbers.

Question Two

Write by your own words the main different between the cohesion and coupling.