AP Computer Science A : Common Data Structures

Study concepts, example questions & explanations for AP Computer Science A

varsity tutors app store varsity tutors android store

Example Questions

Example Question #2 : Arrays

Which of these instantiate a matrix called matrx with 5 columns and 4 rows that takes in integers?

Possible Answers:

int [] [] matrx = new int [] [4];

int [] [] matrx = new int [5] [4];

int [] [] matrx = new int [5] [];

int [] [] matrx = new int [] [5];

int [] [] matrx = new int [4] [5];

Correct answer:

int [] [] matrx = new int [] [4];

Explanation:

You create a matrix also known as a 2 dimensional array the same way you'd instantiate a normal array except the first array space remains blank and you'd insert the number for the amount of rows. Due to the fact that you want 5 columns and 4 rows, you'd only input the 4 into the second array.

Learning Tools by Varsity Tutors