This book is now obsolete Please use CSAwesome instead.

8.16. 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 double each element in the array then print out the new value – so (1,2,3,4,5) should become (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 <i>Check Me</i> button to check your solution.</p>

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 <i>Check Me</i> button to check your solution.</p>

The following program segment should print each element in the array that is even. 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 <i>Check Me</i> button to check your solution. </p>

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 <b>one extra block</b> 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 <i>Check Me</i> button to check your solution. </p>

The following program segment is a method that should return average given an array of integers (the parameter). But, the blocks have been mixed up and include <b>one extra block</b> 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 <i>Check Me</i> button to check your solution. </p>

The following program segment is a method that should return largest integer given an array of integers (the parameter). But, the blocks have been mixed up and include <b>two extra blocks</b> 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 <i>Check Me</i> button to check your solution. </p>

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). But, the blocks have been mixed up and include <b>one extra block</b> 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 <i>Check Me</i> button to check your solution. </p>

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 <b>one extra block</b> 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 <i>Check Me</i> button to check your solution. </p>

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 <b>two extra blocks</b> 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 <i>Check Me</i> button to check your solution. </p>

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 <b>one extra block</b> 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 <i>Check Me</i> button to check your solution. </p>

You have attempted of activities on this page