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

Need help with a program, a 2d array q of int\'s is passed to a method printRow

ID: 3642730 • Letter: N

Question

Need help with a program, a 2d array q of int's is passed to a method printRow to print one of the rows. The # of the row to print is passed as the first parameter( the first row number is 0)

I need to fill in the expressions below. The one (at[1]) should check that the row is in the correct array; and the next one (at[2]) should evaluate to the number of columns of the array.

*Need to fill in where the blank lines are*

public void printRow(int row, int[][] s)
{
if ( row < 0 || row > ____________________________________ ) { // [1]
System.out.printf("printRow: Invalid row number = %d ", row);
System.exit(1);
}
System.out.printf( Row number %d ", row);
for(int c = 0; c < __________________________________ ; c++) { // [2]
System.out.printf("%3d ", s[row][c]);
}
System.out.println();
}
Appreciate the help, very confused.

Explanation / Answer

public void printRow(int row, int[][] s) { if ( row < 0 || row >s[0].length ) { // [1] System.out.printf("printRow: Invalid row number = %d ", row); System.exit(1); } System.out.printf( Row number %d ", row); for(int c = 0; c