Sie sind auf Seite 1von 1

Arrays Practice Problems

(1) Read the entries of an array of 10 integers from a user. Compute x as the average of the 10
entries and then compute the average of those entries that are greater than or equal to x.
Print this final average.

(2) Write a program that takes an array a of integers and returns a new array of the same
length, where each entry is the corresponding value in a multiplied by its index in the array.

(3) Write a program that takes two arrays of integers and returns a new array where the value
at each index is the sum of the corresponding two elements of the given arrays at the same
index. Assume the arrays are of equal length.

(4) Write a program that takes two arrays of integers and returns a new array where the value
at each index is the sum of the corresponding two elements of the given arrays at the same
index. Do not assume the arrays are of equal length. Pretend that the shorter array is
padded with zeros at the end. (For example, if the arrays are of length 3 and 5, your result
should be as if the shorter array had zeros in the "missing" slots.)

(5) Write a program that sets up an array of integers with capacity 20. It should then generate
the 20 entries randomly in turn. Each entry must be an integer between 1 and 20, however it
must also be different from all previous entries in the array. Generate the entries as random
numbers and repeatedly make new numbers until a legal entry value is found. The program
should finish by printing the list of 20 array values that it has selected.

(6) Write a program that takes as its parameter an array of integers and modifies the given
array so that it contains a running sum of its original values. For example, if the array
originally had the values [3 2 4 7], after running your method that array would instead
contain [3 5 9 16].

Das könnte Ihnen auch gefallen