Write a method getRowx that has 2 parameters a twodimensiona
Write a method _getRowx that has 2 parameters, a two-dimensional labeled data and an int labeled _row. Note that row for humans start form The method will return a single dimension array of int [] containing the row of interest. Example, if table! was Then, int[] w = getRowx(table1, 2) would return 4 5 We were asking getRowx to retrun the 2^nd row from tabl1. This is just an method should work on any 2 array and any row.
Solution
public class GetRowFrom2D {
/**
* @param args
*/
public static void main(String[] args) {
int[][] table = { { 1, 2, 3 }, { 4, 5, 6 } };
int[] row = getRowx(table, 2);
if (row != null) {
System.out.print(\"Second row in the table :\");
for (int i = 0; i < row.length; i++) {
System.out.print(row[i] + \" \");
}
}
}
/**
* method to return the array the indicating row
*
* @param data
* @param row
* @return
*/
public static int[] getRowx(int[][] data, int row) {
if (data.length >= row)
return data[row - 1];
else
return null;
}
}
OUTPUT:
Second row in the table :4 5 6
