Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
7 Cards in this Set
- Front
- Back
Multidimensional arrays |
multidimensional arrays are arrays of arrays most common are two-dimensional arrays - tables. |
|
Declaring two dimensional array |
Declaration of array with three rows and two columns, storing integers. int[][] table = new int[3][2]; first row indexes are: [0][0], [0][1] second row index are: [1][0], [1][1] third row indexes are: [2][0], [2][1] |
|
Initializing array using nested loops |
Array storing student’s marks (two marks per student) double[][] marks = new double[10][2]; //10 students for(int row = 0; row < marks.length; row++) { for(int col = 0; col < marks[row].length; col++) { marks[row][col] = 0; //initializing array’s elements to 0 } } |
|
Initializing array using “initializer” list. |
int[][] nums = {{1,2,3}, {4, 5, 6}}; -creates array with two rows and three columns and provides initial values. 1 2 3 4 5 6 |
|
Array Length |
Since multidimensional array is array of arrays, each array could have different length! Number of rows in two-dimensional arrays called A is: int numberRow = array.length Number of columns in nth row is: int numberCol = array[nth].length e.g. myarray[2].length - returns size of 3rd row |
|
Using length variable |
Using nested for loops to enter values into array. int[][] A = new int [x][y]; for(int row= 0; row <A; row++){ for (int col =0; col<A[row].length; col++){ A [row][col] = (int) (Math.random()*10) + 1; } } |
|
Passing Arrays As Parameters |
int [][] sales = new int[100][3]; int total = sum(sales); ... public int sum(int[][] A) { int total = 0; for(int row = 0; row < A.length; row++) { for(int col = 0; col < A[row].length; col++) { total = total + A[row][col]; } } return total; } |