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
Related Q & A:
- what happens internally in a router when lan is configured?Best solution by Server Fault
- What happens to your body when you don't eat?Best solution by Yahoo! Answers
- What happens inside your stomach when you have stomach ache?Best solution by Quora
- What are the yahoo points for? And what happens when I run out of them?Best solution by Yahoo! Answers
- What happens to the temperature when kinetic energy increases?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.