This code would print out the number 7 in the array:
int[][] arr = {{1,2,3}, {4,5,6}, {7,8,9}}
what is arr[2][0]?
This code creates an empty 2D array of integers called nums with shape 2x3
What is int[][] arr = new int[2][3];
This is the syntactical error in the code:
int[][] arr = int[3][4];
What is "missing the keyword new"
This code finds the last (bottom right) value in the array nums
What is:
nums[nums.length-1][nums[0].length-1]
!!! DAILY DOUBLE !!!
This code returns the number of columns in the array nums
what is:
nums[0].length
This is the syntax error in the code:
for(int r = 0; r < arr.length(); r++) {
for(int c = 0; c < arr[0].length(); c++) {
System.out.println(arr[r][c]);
}
}
What is "array.length() should not have parens"
This code prints out the values on the diagonal of a square 2D array, nums
EX:
[1,2,3]
[4,5,6]
[7,8,9]
Should print out 1, 5 and 9
What is:
for(int i = 0; r < nums.length; r++){
System.out.println(nums[i][i]);
}
This code creates an array of integers with shape 3x4 filled with random numbers from 1-10.
What is
int[][] arr = new int[3][4];
for(int r = 0; r < arr.length; r++) {
for(int c = 0; c < arr[0].length; c++) {
arr[r][c] = int(Math.random()*10) + 1;
}
}
This is the syntax error in the code:
int[][] nums = [[1,2,3], [4,5,6], [7,8,9]];
What is "square brackets are incorrect"
!!!DAILY DOUBLE!!!
This code traverses through the array "bob" in reverse order (i.e. bottom right to top left)
for(r = bob.length - 1; r >=0; r--){
for(c = bob[0].length - 1; c >= 0; c--) {
//Some code
}
}
["Alice", "A+"]
["Bob", "B+"]
...
What is:
String[][] studentGrades = new String[20][2];
These are the TWO syntax errors with the following code:
double[] grades = new double[20][20];
for(int r = 0; r<=grades.length; r++){
for(int c = 0; c<=grades[0].length;c++) {
grades[r][c] = c + r;
}
}
What are missing square bracket, index out of bounds error
This code will find the largest value in the array named nums.
What is:
int largestNum = nums[0][0];
for(int r = 0; r < nums.length; r++){
for(int c = 0; c < nums[0].length; c++) {
if(nums[r][c] > largestNum) {
largestNum = nums[r][c];
}
}
}
System.out.println(largestNum);
This code creates a new array inverse, that flips the input array nums vertically
example:
[1,2,3] ==> [4,5,6]
[4,5,6] [1,2,3]
int[][] inverse = new int[nums.length][nums[0].length];
for(int r = 0; r < nums.length; r++){
inverse[r] = nums[nums.length-r-1];
}
This syntax is used to make a 3D array of doubles
What is double[][][] threeD = new double[10][10][10];