Colorado State University

Recitation R11 - Java Arrays
Spring 2015

CS160: Foundations in Programming


The purpose of this lab is to:

Introduction to Arrays

Your TA will introduce arrays and discuss:


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 methods arrayAverage and swapArray.
  3. Create a four element array of doubles called grades that contains the following numbers in this order: 81.2, 92.5, 48.9, 78.8
  4. Create a 6 element array of ints called numbers that contains the following numbers in this order: 12, 42, 33, 67, 92, 58
  5. Create a 9 element array of Strings called arguments without using an array initializer.
  6. Print the length of grades using length.
  7. Print the length of numbers using length.
  8. Print the length of arguments using length.
  9. Print the 4th element of grades.
  10. Print the 2nd element of grades.
  11. Print the 3rd element of numbers.
  12. Set the 1st element of numbers to be 99.
  13. Set the last element of grades to be 90.5
  14. Set the 7th element of arguments to be "HelloThere"
  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 static method called arrayAverage that takes an array of doubles as a parameter 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.

Optional bonus:


Submit your R11.java program to each partner's Checkin.

© 2015 CS160 Colorado State University. All Rights Reserved.