CS 312 - Midterm 2 Review Sheet
Here are some review questions. There will definitely be questions on
the exam that are not similar to the ones below. Re-work examples and
exercises from class and discussion to test your understanding of
different topics. Remember that you will not have your textbook, class
notes, or the compiler to help you write programs on the exam, and
there will be much more time pressure than there is for programming
assignments.

1. Write a method that takes an integer n, and returns a String. Assume
the integer n is an odd integer between 1 and 9. If the returned String
is printed, it should display a box like the one below, when n = 9. The
integers in the last row will be n.

-----1---------333-------55555-----7777777---999999999-

2. Write a method compareEntries that takes two arrays of
integers, and returns the lowest index in which the arrays contain the
same value. If there is no position in the which the two arrays contain
the same values, return -1.
compareEntries({4, 6, -1, 8, 20}, {88, 20, -1, 4, 9, 0}) --> 2
compareEntries({11, 0, 2}, {5, 8, 2, 1}) -->2
compareEntries({6, 7, 8, 9}, {2, 3}) --> -1

public static void printTotals(File grades) throws IOException
{
Scanner reader = new Scanner(grades);
while(reader.hasNextLine())
{
// get the line and create a Scanner
for it
String line = reader.nextLine();
Scanner lineScanner = new Scanner(line);

6. Write a method negativePositive that takes an array of integers, and
returns an array that contains 3 integers. The first value in the
returned array is the number of negative integers in the array, the
second value is the number of zeroes in the array, and the third value
is the number of positive integers in the array.
negativePositive({4, 90, -3, -1, 0, 0, 88, -5, -2}) -> [4, 2, 3]

7. Write a program that prompts the user for a file name, and continues
to prompt the user until the specified file exists and is readable.
Assume the file contains Strings, characters, doubles, etc., all types
of tokens. Create a new file called doubles.txt, and write all
floating-point numbers in the file to this new file.

8. Write a program that prompts the user for 2 integers, m and n. Then
print the squares of these integers, in increasing order, separated by
commas:
Please enter two integers: 5 3
The squares are: 9, 16, 25

12. Prompt the user to enter 10 Strings, and store those strings in an
array. Pass this array of Strings to a method getLengths. getLengths
will return an array that contains the lengths of the strings in the
array.