2026 03 18 Array Practice
A good variety of straightforward array exercises."
-
Make an array
xswith n numbers 101, 102, …q1(3) == {101, 102, 103} -
Total all of the numbers in ys.
int mytot(int[] ys) mytot({10,20,90}) == 120 -
Return the first 5 items of the array. If there are not 5 items, return the whole array.
int[] take5(int [] ws) take5({1,2,3,10,20,30}) == {1,2,3,10,20} take5({6,8}) == {6,8} -
What is the difference between these two declarations?
int[] xs, ys; int xs[], ys; -
Given a string containing only X and O, convert every X to a 1 and every O to a 0.
int[] Xtobin(String str) Xtobin("XOOXXX") == {1,0,0,1,1,1}