| preferred AP College board partner for AP classes
AP Computer Science A/Unit 8: 2D Array
Start Practice Test
Share
easy Solved by 5 students
Dynamic 2D Array Creation
< Prev
Next >

Which of the following is an example of creating a 2D array with dimensions provided as arguments?

public class MatrixCreator {
    public static int[][] createMatrix(int rows, int cols) {
        return new int[rows][cols];
    }
    public static void main(String[] args) {
        int[][] matrix = createMatrix(3, 4);
        System.out.println(matrix.length + "x" + matrix[0].length);
    }
}
A
public class MatrixCreator {
    public static int[][] createMatrix(int rows, int cols) {
        return new int[rows][cols];
    }
    public static void main(String[] args) {
        int[][] matrix = createMatrix(3, 4);
        System.out.println(matrix.length + "x" + matrix[0].length);
    }
}
B
public class MatrixCreator {
    public static int[][] createMatrix(int rows, int cols) {
        return null;
    }
    public static void main(String[] args) {
        int[][] matrix = createMatrix(3, 4);
        System.out.println(matrix.length + "x" + matrix[0].length);
    }
}
C
public class MatrixCreator {
    public static int[][] createMatrix(int rows, int cols) {
        return new int[rows-1][cols-1];
    }
    public static void main(String[] args) {
        int[][] matrix = createMatrix(3, 4);
        System.out.println(matrix.length + "x" + matrix[0].length);
    }
}
D
public class MatrixCreator {
    public static int[][] createMatrix(int rows, int cols) {
        int[][] matrix = new int[rows][cols];
        return matrix;
    }
    public static void main(String[] args) {
        int[][] matrix = createMatrix(3, 4);
        System.out.println(matrix.length + "x" + matrix[0].length);
    }
}
Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer

Question Leaderboard

Not enough data yet to show leaderboard.

APFIVE © 2020.
Email: [email protected]|Privacy Policy