# 9.4. 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 create a 10 by 10 two-dimensional int array. It should fill this array with numbers 0 to 99 from left to right, top row to bottom row and print the output (in row-column order). But, the blocks have been mixed up and contain an extra block that is not needed in the solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the Check Me button to check your solution.

The following program segment should create a 8 by 8 two-dimensional int array. It should fill this array with a checkered pattern of 0s and 1s – starting with a 1 in the top left corner and print the output (in row-column order). But, the blocks have been mixed up and include one extra block that is not needed in a correct solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the Check Me button to check your solution.

The following program segment is a method that should accept a two-dimensional int array and return the sum of all of its values. But, the blocks have been mixed up and include three extra blocks that are not needed in a correct solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the Check Me button to check your solution.

The following program segment is a method that should accept a two-dimensional String array “image” and flip the “image” 180 degrees vertically. For example: </br>

1 2 3 4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4 3 2 1 </br> 1 2 3 4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4 3 2 1 </br> 1 2 3 4&nbsp;&nbsp;->&nbsp;&nbsp;4 3 2 1 </br> 1 2 3 4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4 3 2 1 </br>

But, the blocks have been mixed up and include one extra block that is not needed in a correct solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the Check Me button to check your solution.

The following program segment is a method that should accept a two-dimensional array of ints and edit it such that all even numbers are replaced by zero. But, the blocks have been mixed up and include two extra blocks that are not needed in a correct solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the Check Me button to check your solution.

The following program segment is a method that should accept a two-dimensional array of ints and a desired int and return the number of occurrences of the desired int in the two-dimensional array. But, the blocks have been mixed up and include two extra blocks that are not needed in a correct solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the Check Me button to check your solution.

The following program segment is a method that should accept a two-dimensional int array and return a single dimensional (normal) int array containing the average of each of the columns. But, the blocks have been mixed up and include three extra blocks that are not needed in a correct solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the Check Me button to check your solution.

The following program segment is a method that should accept a two-dimensional int array and return a new two-dimensional int array containing only the odd index rows. But, the blocks have been mixed up and include three extra blocks that are not needed in a correct solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the Check Me button to check your solution.

The following program segment is a method that should accept a two-dimensional String array, in which each row contains the characters of a word. The method should return a single-dimensional (normal) String array containing the words in each row of the two-dimensional array.

Take for example, the input 2d array: { {“b”, “a”, “t”, “h”},

{“t”, “e”, “n”, “s”}, {“j”, “a”, “c”, “k”}, {“l”, “a”, “z”, “y”}}

Resulting array: {“bath”, “tens”, “jack”, “lazy”}

But, the blocks have been mixed up. 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 Me button to check your solution.

The following program segment is a method that should accept a two-dimensional int array, and return a single-dimensional (normal) int array containing the max of each row. But, the blocks have been mixed up and include one extra block that is 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 Me button to check your solution.