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

-What are two-dimensional arrays? -Write a code segment that declares a variable

ID: 3785740 • Letter: #

Question

-What are two-dimensional arrays?

-Write a code segment that declares a variable to reference an array of integers with 10 rows and 20 columns and assigns this variable a new array object.

-Write a code segment that searches a two-dimensional array for a negative integer. The loop should terminate at the first instance of a negative integer in the array, and the variables row and col should be set to its position. Otherwise, if there are no negative integers in the array, the variables row and col should equal the number of rows and columns in the array (we assume that each row has the same number of columns).

-Describe the contents of the array after the following code segment is run:

-Write a code segment that outputs the integers in a two-dimensional array named table. The outputshould begin each row of integers on a new line.

Explanation / Answer

1.) 2-D array like 1-D arrays are used to store a large no. of values using a single variable. The most common use of 2-D array is matrix representation.

2.) Code segment that declares a variable to reference an array of integers with 10 rows and 20 columns and assigns this variable a new array object:

int[][] intArray = new int[10][20]

3.) Code segment that searches a two-dimensional array for a negative integer:

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

{

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

{

if(a[i][j] < 0)

System.out.println("Negative no. is found at position" + i + j );

}

}

4.) Contents of matrix [5][5] is

0 0 0 0 0
0 1 2 3 4
0 2 4 6 8
0 3 6 9 12
0 4 8 12 16

5.) outputs the integers in a two-dimensional array named table

for( i =0; i<table.length; i++)

{

for(j=0; j<table.length; j++)

{

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

}

System.out.print(" ");

}

Hope it helps, do give your response.