DOC PREVIEW
LETU COSC 2103 - Arrays

This preview shows page 1-2-3-4 out of 11 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

ArraysDeclaring and Creating ArraysUsing ArraysThe Array InitializerProcessing Elements of An ArrayHistogram ProgramUsing Array Elements as CountersReferences and Reference ParametersSlide 9Slide 10Multidimensional ArraysArraysChapter 72Declaring and Creating Arrays•Recall that an array is a collection of ____________ all of the same type•Array objects in Java must be created with the key word ______________•Syntax_______________________•Results:–12 integer locations are allocated–They are initialized to 0(null for reference variables, false for boolean)3Using Arrays•View the adapted version of Figure 7.2•Note–Declaration of the array–______________ of memory with new–Initialization of array elements–Use of array attribute (______________)–Printing of array contents4The Array Initializer•A comma separated list of expressions–The ____________________ list–Enclosed in braces•View the Example–Note again, how the array knows __________________________–for (int count = 0 ; count < array.length ; count++) . . .5Processing Elements of An Array•Finding and using the arithmetic mean–_______________ the array, create–Read in values, ___________________–Declare a _________________ variable, initialize –Sum the array, calculate average–_____________ the array–Print results, accessing the array6Histogram Program•Uses the JOptionPane output•Use the value in the array to–Print the ______________–Print a string of asterisks for _____________ of size of the value•View Figure 7.7, listen to author's explanation7Using Array Elements as Counters•Recall program which tested random number generator (Figure 6.7)–Used 6 ___________________–Used ___________ statement to increment–At the time we noted the inefficiency•Consider a new version of the program–Uses _______________ to total the number of rolls of each number 1 – 6–______________ statement needed•View Figure 7.78•In Java, primitive-type variables are always passed by ____________–___________ data only•Objects are not passed to methods–______________ to objects are passed–The reference is passed by value•With a reference to the object the method can ___________ the object directlyReferences and Reference Parameters__________9References and Reference Parameters•Passing arrays by reference–Improves ______________________–Saves ____________•Initialization of large array not required–Saves ____________•Use memory already occupied by array•No new memory allocation required–View example program, Figure 7.910Using Arrays•Sorting Arrays–Recall previous example•Searching Arrays–____________ search (see example)•Step through array until desired value located–Binary search•Array must be _________________•Look in ______________, then above or below–Look in middle of sub-section then above or below–Etc.11Multidimensional Arrays•Java does not support multidimensional arrays directly•Does allow declaration of arrays whose elements are _______________!•Note that _________ may have differing numbers of columns•View Figure 7.14int b[][];b = new int[ 2 ][ ]; // allocate rowsb[ 0 ] = new int[ 5 ]; // allocate columns for row 0b[ 1 ] = new int[ 3 ]; // allocate columns for row


View Full Document

LETU COSC 2103 - Arrays

Documents in this Course
Arrays

Arrays

16 pages

Templates

Templates

17 pages

Methods

Methods

22 pages

Methods

Methods

22 pages

Load more
Download Arrays
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Arrays and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Arrays 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?