Skip to main content

Section 4.19 Unit 4A - Toggle Code Practice 4a Arrays (4.1-4.6)

For each of the coding problems below, write your own solution. If you get stuck, click the Get Help button for a personalized mixed-up code problem built from your current attempt.

Activity 4.19.1.

Write a loop that traverses the array arr from 0 to less than the length of the array. In the loop, double each element in the array arr and print out each new value on the same line separated by β€œ, β€œ. The finished code should print β€œ2, 4, 6, 8, 10, β€œ.

Activity 4.19.2.

Write a for loop that fills an array with elements that count up from 0 to 50 by 5 (0 5 10 15 20 … 50) and prints out each element on a separate line.

Activity 4.19.3.

Write an enhanced for each loop to traverse the array and print out an element if it is even.

Activity 4.19.4.

Finish the method to return the smallest integer in an array arr given as the parameter.

Activity 4.19.5.

Finish the method to return the average of the elements in an array arr given as the parameter. The method should return the average.

Activity 4.19.6.

Finish the method to return the largest integer in an array arr given as the parameter.

Activity 4.19.7.

Finish the method that given an array as a parameter, returns the elements β€œright shifted” by one – so {6, 2, 5, 3} returns {3, 6, 2, 5}.

Activity 4.19.8.

Finish the method to 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}.

Activity 4.19.9.

Finish the method that should return string array that is in reverse order – so {"b", "a", "z"} should return {"z", "a", "b"}.

Activity 4.19.10.

Finish the method so that it copies the first half of an array given as an argument to the method into a result array which is returned.
You have attempted of activities on this page.