CSU Banner

CS 163/164, Spring 2018

Lab 11 - Array Practice

Tuesday, Feb. 27th or Wednesday, Feb. 28th


Objectives of this Lab

  1. Introduce you to arrays,
  2. reinforce the basics of arrays, and
  3. practice reading instructions carefully.

Introduction

Your TA will introduce Java array basics:


Array Practice, Practice, and more Practice

Do the following steps in order (and ask questions!):

  1. Create a new R11 project in Eclipse and an associated class.
  2. Put everything that follows into the main method except the method arrayAverage.
  3. Create a 5 element array of doubles called grades that contains the following numbers in this order: 81.2, 92.5, 48.9, 78.8, and 45.5.
  4. Create a 7 element array of ints called numbers that contains the following numbers in this order: 12, 42, 33, 67, 92, 58, and 33.
  5. Create a 9 element array of Strings called arguments without using an array initializer.
  6. Print (on one line) the length of grades using length.
  7. Print (on one line) the length of numbers using length.
  8. Print (on one line) the length of arguments using length.
  9. Print (on one line) the first element of grades.
  10. Print (on one line) the third element of grades.
  11. Print (on one line) the last element of numbers.
  12. Set the second to last element of grades to be 90.5.
  13. Set the third element of numbers to be 99.
  14. Set the first six elements of arguments to be "Java", and the rest to be "C++".
  15. Use a loop to print each element of grades on the same line, separated by commas (with a trailing comma).
  16. Use a loop to print each element of numbers on the same line, separated by spaces (with a trailing space).
  17. Use a loop to print each element of arguments on the same line, separated by an underscore (with a trailing underscore).
  18. Print the contents of grades using Arrays.toString(grades);
  19. Print the contents of numbers using Arrays.toString(numbers);
  20. Print the contents of arguments using Arrays.toString(arguments);
  21. FINAL STEP: Write a public static called arrayAverage that takes an array of doubles as a parameter.
  22. and returns the average as a double. Print the result of calling arrayAverage with the array grades. with exactly 3 digits after the decimal point.


Show your R11.java to the TA for grading.


CS Banner
CS Building