java - Printing each elements of one row on separate lines? -


this question: assume two-dimensional array of ints called 'myints'. write code snippet print each of elements of row m on separate line. may assume m not out of bounds.

this work have done not sure going in right direction...

for (int = 0; < myints.length; i++) {     (int j = 0; j < myints[i].length; j++) {         system.out.print (myints[i][j]);          if(j < myints[i].length - 1) {             system.out.print(" ");         }     }      system.out.println(); } 

because requirement print values of given row m, think need single for loop, iterate on single row:

public void printrow(int[][] array, int m) {     (int i=0; < array[m].length; ++i) {         system.out.println(array[m][i]);     } } 

i didn't bother checking bounds of input m, because said don't need to. in case, printrow() throw arrayindexoutofboundsexception should index m out of bounds.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -