6.6. Mixed Up Code Practice

Try to solve each of the following. Click the Check Me button to check each solution. You will be told if your solution is too short, has a block in the wrong order, or you are using the wrong block. Some of the problems have an extra block or two that aren’t needed in the correct solution. Try to solve these on your phone or other mobile device!

The following program segment should loop from 0 to less than the length of the array and double each element in the array arr and also print out each new value on the same line separated by “, “. The finished code should print “2, 4, 6, 8, 10, “. But, the blocks have been mixed up. Drag the blocks from the left and put them in the correct order on the right. Click the Check button to check your solution.

The following program segment should fill an array with elements that count up from 0 to 50 by 5 (0, 5, 10, 15, 20…). But the blocks have been mixed up. Drag the needed blocks from the left and put them in the correct order on the right. Click the Check button to check your solution.

The following program segment should print each element in the array that is even using an enhanced for each loop. But, the blocks have been mixed up. Drag the blocks from the left and put them in the correct order on the right. Click the Check button to check your solution.

The following program segment is a method that should return the smallest integer given an array of integers (the parameter). But, the blocks have been mixed up and include one extra block that is not needed in a correct solution. Drag the blocks from the left and put them in the correct order with the correct indentation on the right. Click the Check button to check your solution.

The following program segment is a method that should return the average given an array of integers (the parameter). But, the blocks have been mixed up and include one extra block that is not needed in a correct solution. Drag the blocks from the left and put them in the correct order with the correct indentation on the right. Click the Check button to check your solution.

The following program segment is a method that should return the largest integer given an array of integers (the parameter). But, the blocks have been mixed up and include two extra blocks that are not needed in a correct solution. Drag the needed code from the left to the right and put them in order with the correct indention so that the code would work correctly. Click the Check button to check your solution.

The following program segment is a method that should return an integer array that is “right shifted” by one – so {6, 2, 5, 3} returns {3, 6, 2, 5} (the parameter). Note that the method return type is int[] which means it will return an int array. But, the blocks have been mixed up and include one extra block that is not needed in a correct solution. Drag the blocks from the left and put them in the correct order on the right. Click the Check button to check your solution.

The following program segment is a method that should return a new array of length 2 containing the middle two elements of a given array of integers of even length (the parameter) – so {1,2,3,4} should return {2,3}. But, the blocks have been mixed up and include one extra block that is not needed in a correct solution. Drag the blocks from the left and put them in the correct order on the right. Click the Check button to check your solution.

The following program segment is a method that should return string array that is in reverse order – so {“b”, “a”, “z”} should return {“z”, “a”, “b”}. But, the blocks have been mixed up and include two extra blocks that are not needed in a correct solution. Drag the blocks from the left and put them in the correct order on the right. Click the Check button to check your solution.

The following program copies the first half of an array given as an argument to the method into a result array which is returned. But, the blocks have been mixed up and include one extra block that is not needed in a correct solution. Drag the blocks from the left and put them in the correct order on the right. Click the Check button to check your solution.

You have attempted of activities on this page