11.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 method should reverse the order of the characters in the given string – so β€œabcd” should become β€œdcba”. 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 Me button to check your solution.

The following method should multiply the two passed-in positive integers (using the fact that multiplcation is repeated addition) – so multipy(3, 4) should become 12 (3+3+3+3). 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.

Before you keep reading...

Making great stuff takes time and $$. If you appreciate the book you are reading now and want to keep quality materials free for other students please consider a donation to Runestone Academy. We ask that you consider a $10 donation, but if you can give more thats great, if $10 is too much for your budget we would be happy with whatever you can afford as a show of support.

The following method should add up all of the elements in the passed-in array – so {1,2,3,12} should return 18 (Note when the method is called, the index will always start off as 0). 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 method should remove any occurrence of an asterisk β€œ*” from a passed-in string – so β€œab*c**d” should become β€œabcd”. 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 Me button to check your solution.

The following method should return the base multiplied power times. In otherwords, the base ^ power – so exponent(2, 4) should return 16. 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 method should return the number of times β€œ5” is an element in the passed-in array – so {1, 5, 7, 14, 5} will return 2 (Note that when the method is called the index will always start off as 0). 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 method should repeat the passed-in string a set number of times – so repeatThis(β€œhi”, 3) should return β€œhihihi”. 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 method should return number of times the character β€œ x β€œ is in a String – so findNumX(β€œxHihxixx”) should return 4. 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 method should return a string counting from 1 to the specified number – so countTo(4) should return β€œ1…2…3…4…”. 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 method should take an passed-in number and return a string such that only the even numbers are still present. All of the odd digits should be replaced with a β€œ_” – so 4321 should become β€œ4_2_”. 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.

You have attempted 1 of 11 activities on this page