Java Reference
In-Depth Information
16. Write a method called append that accepts two integer arrays as parameters and returns a new array that contains the
result of appending the second array's values at the end of the first array. For example, if arrays list1 and list2
store {2, 4, 6} and {1, 2, 3, 4, 5} respectively, the call of append(list1, list2) should return a new array con-
taining {2, 4, 6, 1, 2, 3, 4, 5}. If the call instead had been append(list2, list1) , the method would return an
array containing {1, 2, 3, 4, 5, 2, 4, 6}.
17. Write a method called vowelCount that accepts a String as a parameter and produces and returns an array of inte-
gers representing the counts of each vowel in the string. The array returned by your method should hold five ele-
ments: the first is the count of As, the second is the count of Es, the third Is, the fourth Os, and the fifth Us. Assume
that the string contains no uppercase letters. For example, the call vowelCount("i think, therefore i am")
should return the array {1, 3, 3, 1, 0}.
18. Write a method called wordLengths that accepts a Scanner for an input file as its parameter. Your method should
open the given file, count the number of letters in each token in the file, and output a result diagram of how many
words contain each number of letters. For example, consider a file containing the following text:
Before sorting:
13 23 480 -18 75
hello how are you feeling today
After sorting:
-18 13 23 75 480
are feeling hello how today you
Your method should produce the following output to the console. Use tabs so that the stars line up:
1: 0
2: 6 ******
3: 10 **********
4: 0
5: 5 *****
6: 1 *
7: 2 **
8: 2 **
Assume that no token in the file is more than 80 characters in length.
19. Write a method called matrixAdd that accepts a pair of two-dimensional arrays of integers as parameters, treats the arrays
as two-dimensional matrixes, and returns their sum. The sum of two matrixes A and B is a matrix C , where for every row i
and column j ,C ij
A ij
B ij . You may assume that the arrays passed as parameters have the same dimensions.
Programming Projects
1. Java's type int has a limit on how large an integer it can store. This limit can be circumvented by representing an
integer as an array of digits. Write an interactive program that adds two integers of up to 50 digits each.
2. Write a game of Hangman using arrays. Allow the user to guess letters and represent which letters have been
guessed in an array.
Search WWH ::




Custom Search