|
| |
Arrays - Test Review
- Answer each of the following: Solutions
- Lists of values can be stored in __________.
- The elements of an array are related by the fact that they have the
same __________ and __________.
- The number used to refer to a particular element of an array is called
its __________.
- Not for this test. This is a "Challenge Question" only. The process of placing the elements of an array in order is called
__________ the array.
- State whether each of the following is true or false. If false, explain
why. Solutions
- An array can store many different types of values.
- An array subscript should normally be of data type double.
- Not for this test. This is a "Challenge Question" only. An array that is passed to a method and modified in
that method will contain the modified value when the called method
completes execution.
- Answer the following questions regarding an array called prices.
Solutions
- Define a constant variable NUM_ELEMENTS of type int with a value of
10.
- Declare an array with NUM_ELEMENTS elements of type double and
initialize the elements to 0.
- Name the third element of the array.
- Refer to array element 3.
- Assign the value 1.754 to array element 9.
- Assign the value 45.71 to the seventh element of the array.
- Sum all the elements of the array using a for loop. Define the integer
variable j as the control variable for the loop.
- Write Java statements to accomplish each of the following: Solutions
- Display the value of the seventh element of String array letters.
- Initialize each of the five elements of the integer array h
to 8.
- Copy the 11-element array j into the first portion of array c
containing 34 elements.
- Create an array x with 100 elements. Solutions
- Declare and allocate memory for x.
- Use a for loop to initialize the elements as follows:
Element 0 contains the value 100. Element 1 contains the value 99, etc.
- Find the total of all the elements in x.
- Find and display the average of the values in x.
- This is a "Challenge Question" only. Have the user create a method that will allow the user to ask for a cell number (subscript) and then
print the contents of the cell. Loop until a -1 is entered.
- Not for 2012 test. This is a "Challenge Question" only. Create a java application that will complete the following set of related
arrays. When given the contents of the arrays itemName[ ], quantity[ ], and
cost[ ], calculate the values in total[ ] and then display the 4
arrays. Solutions

- Set up an array with the values 62, 38, 75, 93, and 83. Write a java
application to find and display: Solutions
- the average;
- Not for 2012 test. This is a "Challenge Question". the largest value.
- Not for 2012 test. This is a "Challenge Question". the smallest value;
- Create and initialize two arrays of Strings. The two arrays should each
have the same number of entries. Initialize the first array with adjectives
(e.g. round, fat, good, bad, funny, green.) Initialize the second array with
the same number of nouns (e.g. puppy, kitten, tree, apple, coffee, cup.)
Randomly pick an adjective from the first array and a noun from the second
and create similes, such as round as a puppy, or green as a tree.
The program should create some funny, but not rude similes. Solutions
- For an integer array named numbers:
- the array should hold 25 elements
- load the array with random integers between -10 and 10
- count and display the number of 10s
- find the average of the entries
- print out the cells that contain a number that is divisible by 3
- display the entire array in columns of 5
- Not for 2012 test. This is a "Challenge Question" only. use the bubble sort to sort and display the array (note that the
sorting algorithm is not on the test)
- This is a "Challenge Question" only.For an integer array named histograpm:
- Load the 50 elements with random numbers from 0 to 9.
- Count the number of 0s, 1s, 2s, etc.
- Display a histogram of the results. For 0 print a *. On the next line
for every 1 print a *, etc.
0: **************
1: ***********
2: ****
3: *****
4: ***********
5: ****
6: *****
7: ***********
8: ****
9: *****
Note that there should be a total of 50 stars.
Source: Deitel, H.M. and Deitel P.J. Java: How to Program. 3rd ed. Upper Saddle River, New
Jersey. Prentice Hall.1999.
ISBN 0-13-012507-5, p 303-304 and others.
|