In: Computer Science
Write a program which shows how two-dimensional arrays which contain multiple copies of your id number and age are passed to methods. Explain in your own words each method and class used in the program.
My id number is 12133149
Thanks for the question. Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks! =========================================================================== public class TwoDArray { public static void main(String[] args) { // creat a 2D array with 3 rows and 2 columns // column 1 (index 0) will be store my id : 12133149 // column 2 (index 1) will be store my age : 20 int myData[][] = new int[3][2]; // fill the 2d array with my id and age myData[0][0] = 12133149; myData[0][1] = 20; myData[1][0] = 12133149; myData[1][1] = 20; myData[2][0] = 12133149; myData[2][1] = 20; // will pass the 2D array to print2DArray mehtod which will display the 2D array print2DArray(myData); } private static void print2DArray(int[][] myData) { // fetch how many rows the 2D array contains for (int row = 0; row < myData.length; row++) { System.out.println("Row #" + (row + 1)); //fetch how many columns each row contains for (int col = 0; col < myData[row].length; col++) { // display the values System.out.println("Col #" + (col + 1) + ", Value: " + myData[row][col]); } } } }
====================================================================