Test: Computer Science

Consider the following code:

int[] vals = {6,1,41,5,1};

int[][] newVals = new int[vals.length][];

for(int i = 0; i < vals.length; i++) {

    newVals[i] = new int[vals[i]];

    for(int j = 0; j < vals[i];j++) {

        newVals[i][j] = vals[i] * (j+1);

    }

}

1.

What does the code above do?

The code creates a 2D array that contains all multiples from 1 to 5 for the members of vals.

It performs a matrix multiplication on vals and newVals, storing the final result in newVals.

It sums the values in vals, placing the outcome in newVals.

The code creates a 2D array that contains the multiples for the members of vals, using each of those values to determine the number of multiples to be computed.

It creates a 2D matrix with the vals array for every row.

1/1 questions

0%

Access results and powerful study features!

Take 15 seconds to create an account.
Start now! Create your free account and get access to features like:
  • Full length diagnostic tests
  • Invite your friends
  • Access hundreds of practice tests
  • Monitor your progress over time
  • Manage your tests and results
  • Monitor the progress of your class & students
By clicking Create Account you agree that you are at least 13 years old and you agree to the Varsity Tutors LLC Terms of Use and Privacy Policy.
Learning Tools by Varsity Tutors