1) Which of the following would classify as volatile memory:

advertisement
CSE 1001
Array Exercises
1) Give a Java method that has two integer arrays as parameters. The method should create and return a
third array containing all of the elements from the two arrays appended together. For example, if the arrays
contained:
12
3
9
30
2
5
24
3
0
10
Then the returned array would be:
12
3
9
30
2
5
24
3
0
10
2) Give a Java method that has two integer arrays as parameters. For this problem assume that the arrays
(individually) contain no duplicates. The method should create and return a third array containing the “set
difference” of the two arrays, i.e., an array containing all of the elements from the first array with all of the
elements of the second array removed. For example, if the arrays contained:
12
3
9
30
2
9
24
3
0
10
Then the returned array would be:
12
30
Note that elements in the second array that are not in the first array should be ignored by the method, e.g.,
2, 24, 0 and 10 from the above example. Also note that the order of the elements in the returned array does
not matter.
3) Give a Java method that has two integer arrays as parameters. For this problem assume that the arrays,
individually, contain no duplicates. The method should create and return a third array containing the “set
intersection” of the two arrays, i.e., an array containing all of the elements that appear in both arrays. For
example, if the arrays contained:
12
3
9
30
2
9
24
3
0
30
Then the returned array would be:
3
9
30
As with the previous exercise, note that the order of the elements in the returned array does not matter.
4) Give a Java method that has one integer array as a parameter. The method should construct and return a
second array that contains all of the elements from the first array, but with duplicates removed. For
example, if the array passed in contained:
2
9
2
3
0
9
Then the returned array would be:
2
9
3
0
5) Give a Java method that has three parameters: an array of integers, an array of strings, and an individual
string. The idea is that all locations in the second array specified in the first array are reassigned the string
value passed in as the third parameter. For example, if the first array contains:
2
5
25
3
The second array contains:
dog
cat
cow
mouse
horse
ant
fly
hamster
flower
car
And the third parameter is “mud,” then the second array is modified as follows:
dog
cat
mud
mud
hours
mud
fly
hamster
flower
car
Note that if an invalid position is specified in the first array, then the method will simply ignore that value,
e.g., 25 in the above example.
Download