Homework - Arrays

  1. Write the statements to declare an int array called nums with 40 elements. Write the statements to store the values 1 through 40 in the elements of nums, add 10 to each entry of the array nums, then print nums.

  2. Write a function printStrings that has an array of Strings as the parm, which will print the array. Make sure that your function only prints those array elements that actually point to String objects.

  3. Write the statements to declare an array of 10 Strings. Store the words "first", "second", "third", "fourth", "fifth" in the array, and call printStrings to print your array.

  4. Write the statements to declare an array of 3 Time objects, store a Time in each array element, and print the array.

  5. Write the statements to declare a 2D array of ints with 10 rows and 20 columns.

  6. Write a statement which will print the number of rows in a 2D array called values.

  7. Write a statement which will print the number of columns in a 2D array called values.

  8. Write a function called setRow that sets the elements in one row of a 2D array of ints. The parameters to the function are the array, the value that should be stored in each element of the row, and the row whose elements should be set.

  9. Write the statements to declare a 2D array of ints with 100 rows and 50 columns, and then call setRow to set all rows of the array to contain the value 100.


Email Me | Office Hours | My Home Page | Department Home | MCC Home Page