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%
Learning Tools by Varsity Tutors