What is a Key Matrix?

Which of the following best describes what happens to this matrix when the loop is executed?

  • Consider this code fragment: int[][] m = new int[ 10 ][ 10 ]; int k; for ( k = 0 ; k < 10 ; k++ ) { m[ k ][ k ] = 0; } The code begins by declaring and initializing a two-dimensional array m. Recall that a two-dimensional array is often referred to as a matrix. Which of the following best describes what happens to this matrix when the loop is executed? 1. All entries of the matrix are set to zero. 2. One entry of the matrix is set to zero. 3. One column of the matrix is set to zero. 4. One row of the matrix is set to zero. 5. One diagonal of the matrix is set to zero. I put 2 and got it wrong. Does anyone know how to get the right answer? If so can you explain it to me? I really need to understand this chapter.. :)

  • Answer:

    5 k will be from 0 to 9 so it'll only set a diagonal to 0 m[0][0] m[1][1] m[2][2] ... m[9][9] 0 - - - - - - - - - - 0 - - - - - - - - - - 0 - - - - - - - - - - 0 - - - - - - - - - - 0 - - - - - - - - - - 0 - - - - - - - - - - 0 - - - - - - - - - - 0 - - - - - - - - - - 0 - - - - - - - - - - 0

Sam at Yahoo! Answers Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.