Week 2 – Optional Exercises

1. Write a method that takes two filenames and copies the contents of the first file to the second. You may assume that the file contains text (not binary) data.

2. Write a method that counts the number of words in a file. Here, a word is any contiguous sequence of non-whitespace characters.

3. Write a method that reads a matrix of integers from standard input and returns it as a 2-dimensional array. The input will be formatted like this:

3 4
3 2 6 8
0 1 -3 8
2 2 7 0

Above, the first line contains the number of rows and columns in the matrix. Each row appears by itself on a subsequent line.

4. Write a method that takes a 2-dimensional array representing a matrix of integers and returns the transpose of the matrix.

5. A magic square is a square matrix of integers with the following properties:

Write a method that takes a 2-dimensional array representing a square matrix of integers, and returns true if it is a magic square, false otherwise.