Skip to main content\(
\newcommand{\lt}{<}
\newcommand{\gt}{>}
\newcommand{\amp}{&}
\definecolor{fillinmathshade}{gray}{0.9}
\newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}}
\)
Section 4.20 Arrays Code Practice
Subsection 4.20.1 Practice Problems
Activity 4.20.1.
Fix the following code so that it prints every other value in the array
arr1 starting with the value at index 0.
Activity 4.20.2.
Fix the following to print the values in the array
a1 starting with the value at the last index and then backwards to the value at the first index.
Activity 4.20.3.
Rewrite the following code so that it prints all the values in an array
arr1 using a for-each loop instead of a
for loop.
Activity 4.20.4.
Finish the following code so that it prints out all of the odd values in the array
a1. Hint: use % to check for odd values.
Activity 4.20.5.
Finish the following method
getSum to return the sum of all values in the passed array.
Activity 4.20.6.
Finish the following method to return the sum of all of the non-negative values in the passed array.
Activity 4.20.7.
Finish the following code to print the strings at the odd indices in the array.
Activity 4.20.8.
Finish the method
getSumChars below to return the total number of characters in the array of strings
strArr.
Activity 4.20.9.
Finish the method
findMin so that it finds and returns the minimum value in the array.
Activity 4.20.10.
Finish the method
getAverage to calculate and return the average of all of the values in the array.
Subsection 4.20.2 More Practice
Here are problems without loops
Here are problems with loops
You have attempted
of
activities on this page.