Midterm 3 Review Stuff

Everybody loves practice problems, right? OK, not everybody. But if you want practice problems for the test, here you go!

1. Write a procedure fiboArray that takes an array of ints as its input and populates it with the Fibonacci numbers. Positions 0 and 1 should be assigned values of 1 and subsequent elements in the array should be the sum of the previous two elements.

2. Write fiboArrayList for an ArrayList<Integer>. Note that you will need a second argument of type int, which will indicate how many elements should be put into the ArrayList. A precondition for calling fiboArrayList is that this number must be at least 2.

3. Write concatenateArray that takes an array of Strings and returns a single String containing all of the elements concatenated.

Example:

String[] strs = new String[4];
strs[0] = "Now";
strs[1] = "here";
strs[2] = " ";    // String contains a single blank
strs[3] = "Man";
System.out.println(concatenateArray(strs));  // prints "Nowhere Man"

4. Write a method that takes in a two-dimensional array of doubles and returns the sum of all of its elements. Hint: remember that if you have an array as shown below:

double[][] d = new double[5][7];

then d.length is 5 and d[0].length is 7.