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

Which of the following code segments correctly defines and utilizes a method to create a two-dimensional int array with dimensions specified by its arguments?

A
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);
    }
}
B
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);
    }
}
C
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);
    }
}
D
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);
    }
}
Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1bommasam00014 1m 44s -34
#2ajcantuwilson032501 2m 00s -130
#3varunrajaram101 4m 37s -287
#4psak1201 16m 32s -1,002
Items per page:
10
1 – 4 of 4
No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy