Arrays Output
2D Array
More on Arrays and 2D arrays
Key Words
100


int[][] arr = {
    {1, 2},
    {3, 4},
    {5, 6}
};

for (int[] row : arr) {
    row[0] *= 2;
}

for (int[] row : arr) {
    for (int val : row) {
        System.out.print(val + " ");
    }
}

2 2 6 4 10 6

100

This expression gives the number of columns in a rectangular 2D array called arr.

What is arr[0].length?

100

This is what happens when you try to access a value at an index that doesn't exist for an array.

What is IndexOutofBounds Runtime Error?

100

Key words used when creating objects.

What is new?

200

What is the Outuput?

int[][] arr = {
    {1, 2, 3},
    {4, 5, 6},
    {7, 8, 9}
};

for (int r = 0; r < arr.length; r++) {
    for (int c = 0; c < arr[r].length; c++) {
        if (r == c) {
            System.out.print(arr[r][c] + " ");
        }
    }
}

1 5 9

200

What does this code output? 

int[][] arr = {
    {1, 2, 3},
    {4, 5, 6}
};

for (int[] row : arr) {
    for (int val : row) {
        val += 5;
    }
}

for (int[] row : arr) {
    for (int val : row) {
        System.out.print(val + " ");
    }
    System.out.println();
}

1 2 3

4 5 6

200

Default values for values stored by int array objects if not explicitly specified

What is 0?

200

Key word to indicate that a field should be shared across objects. Also indicates that a method can be called without creating an object beforehand.

What is static?

300

What is the output? 


int[][] arr = {
    {3, 1, 4},
    {1, 5, 9},
    {2, 6, 5}
};

for (int i = 0; i < arr.length; i++) {
    System.out.print(arr[i][i] + " ");
}

3 5 5

300

What type of loop would be best to use when summing values in each column.

Column Major 

300

The result of:

Pokemon[] p1 = {new Pokemon("mew", 200), new Pokemon("pichu", 20)};

Pokemon[] p2 = {new Pokemon("mew", 200), new Pokemon("pichu", 20)};

System.out.println(p1 == p2);

What is false?

300

This Java keyword can be used on a class, method, or variable to make it accessible from any other class.

What is public?

400

What is the output? 

int[][] arr = {
    {2, 4, 6},
    {1, 3, 5},
    {7, 8, 9}
};

int sum = 0;

for (int r = 0; r < arr.length; r++) {
    sum += arr[r][0];
}

System.out.println(sum);

10

400

This expression accesses the bottom-right element of a rectangular 2D array.

What is arr[arr.length - 1][arr[0].length - 1]?

400

The result of:

int[] nums = {1, 2, 3};

for(int i = 0; i < 10; i--){

      System.out.println(nums[i] + 2);

}

What is error?

400

This keyword is used to refer to the current object inside a class.

What is this?

500

The result of this:

Pokemon[] myTeam = {new Pokemon("mew", 200), new Pokemon("gible", 30)};

int[] nums = {5, 5, 5};
for(int num: nums){

      num = 10;

}
for(Pokemon mon: myTeam){

      mon.editHp(-10);

}

System.out.println(nums[0]);

System.out.println(myTeam[0].getHp());

What is:
5
190
?

500

The result (what nums ends up storing) of this:

int[][] nums = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
for(int i = 2; i >= 0; i--){

      for(int j = 2; j >= 0; j--){

                 if(!(i == 0 && j == 0)){

                        if(j != 0){

                             nums[i][j] += nums[i][j - 1];

                         }

                         else{

                              nums[i][j] += nums[i - 1][2];

                         }

                 }

      }

}

The result is:

[[1, 3, 5],
[7, 9, 11],
[13, 15, 17]]

500

Default values for values stored by non primitive type array objects if not explicitly specified

What is null?

500

Keyword that makes it so that you can only read from a variable once it is initially assigned a value.

What is final?