1D Arrays
March 9th, 2016
Lecture Code
1D Arrays
- Declaration, e.g. int[] census;
- Allocation, e.g. census = new int[2016];
- Access, e.g. census[2015]
- Size, e.g. census.length
- Initialization
- for each looping, e.g. for (int censusForYear: census) { ... }
- Slides
- Oracle Documentation
Class Exercise
Define a class called ArrayStuff that provides the following
functionality.
- The constructor is called with a number n that specifies
the size of the array. Each item in the array should be a double
initialized randomly to a number between 0.0 and 20.0.
- A method printArray exists that prints each element of the array.
- A method largestItem exists that finds and returns the biggest
element of the array.