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