Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Which of the following statements represent a valid way to create a 2D array? an

ID: 3725607 • Letter: W

Question

Which of the following statements represent a valid way to create a 2D array? and why? Select all that apply.

String [][] allCompanions = new String[100];

String [][] allCompanions = {{"Susan", "Barbara"}};

String [][] allCompanions = {"Susan", "Barbara"}, {"Polly", "Ben"};

String [][] allCompanions = {{"Susan", "Barbara", "Ian"}, {"Polly", "Ben"}};

String [][] allCompanions = new String[13][];

String [][] allCompanions = new String[][11];

Which of the following statements represent a valid way to create a 2D array? and why? Select all that apply.

Answers:

String [][] allCompanions = new String[100];

String [][] allCompanions = {{"Susan", "Barbara"}};

String [][] allCompanions = {"Susan", "Barbara"}, {"Polly", "Ben"};



String [][] allCompanions = {{"Susan", "Barbara", "Ian"}, {"Polly", "Ben"}};


String [][] allCompanions = new String[13][];

String [][] allCompanions = new String[][11];

Explanation / Answer

Answer:

String [][] allCompanions = {{"Susan", "Barbara"}};

String [][] allCompanions = {{"Susan", "Barbara", "Ian"}, {"Polly", "Ben"}};

String [][] allCompanions = new String[13][];

are valid 2D array statements.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote