hts.StevenWood.com

[ Last Page ]

Arrays - Test Review

  1. Answer each of the following: Solutions
    1. Lists of values can be stored in __________.
    2. The elements of an array are related by the fact that they have the same __________ and __________.
    3. The number used to refer to a particular element of an array is called its __________.
    4. 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.
  2. State whether each of the following is true or false. If false, explain why. Solutions
    1. An array can store many different types of values.
    2. An array subscript should normally be of data type double.
    3. 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.
  3. Answer the following questions regarding an array called pricesSolutions
    1. Define a constant variable NUM_ELEMENTS of type int with a value of 10.
    2. Declare an array with NUM_ELEMENTS elements of type double and initialize the elements to 0.
    3. Name the third element of the array.
    4. Refer to array element 3.
    5. Assign the value 1.754 to array element 9.
    6. Assign the value 45.71 to the seventh element of the array.
    7. Sum all the elements of the array using a for loop. Define the integer variable j as the control variable for the loop.
  4. Write Java statements to accomplish each of the following:  Solutions
    1. Display the value of the seventh element of String array letters.
    2. Initialize each of the five elements of the integer array h to 8.
    3. Copy the 11-element array j into the first portion of array c containing 34 elements.
  5. Create an array x with 100 elements.    Solutions
    1. Declare and allocate memory for x.
    2. Use a for loop to initialize the elements as follows: 
      Element 0 contains the value 100. Element 1 contains the value 99, etc.
    3. Find the total of all the elements in x.
    4. Find and display the average of the values in x.
    5. 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.
  6. 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

  7. Set up an array with the values 62, 38, 75, 93, and 83. Write a java application to find and display:    Solutions
    1. the average;
    2. Not for 2012 test. This is a "Challenge Question". the largest value.
    3. Not for 2012 test. This is a "Challenge Question". the smallest value;
  8. 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
  9. For an integer array named numbers:
    1. the array should hold 25 elements
    2. load the array with random integers between -10 and 10
    3. count and display the number of 10s
    4. find the average of the entries
    5. print out the cells that contain a number that is divisible by 3
    6. display the entire array in columns of 5
    7. 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)
  10. This is a "Challenge Question" only.For an integer array named histograpm:
    1. Load the 50 elements with random numbers from 0 to 9.
    2. Count the number of 0s, 1s, 2s, etc.
    3. 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.

 
[Last Page]
All material on this site is copyright © 1997- by Steven Wood or as credited. All right reserved. Use of this site indicates you agreement with the  terms of use.
Send comments or questions to about this page.
Every attempt has been made to credit work under copyright. If there are any claims that copyright has been missed please contact the .
+SDG+