Aalborg Media Lab 2-May-15 Exercises/Summary Lecture 10 Summary, Exercises
Aalborg Media Lab 2-May-15 Summary of Arrays SD8 has focused on: –array declaration and use –passing arrays and array elements as parameters –arrays of objects –multidimensional arrays –the ArrayList class –polygons and polylines
Aalborg Media Lab 2-May-15 Array Summary An array is an ordered list of values An array of size N is indexed from zero to N-1 scores The entire array has a single name Each value has a numeric index This array holds 10 values that are indexed from 0 to 9
Aalborg Media Lab 2-May-15 Declaring and Using Arrays Declare integer array; int[] scores = new int[10]; Assigning integer to array; scores[index] = 2554; Retrieving information from array for (int i = 0; i < scores.length; i ++) { scores[i] = 0; }
Aalborg Media Lab 2-May-15 Accessing Array Data scores for (int i = 0; i < scores.length; i ++) { scores[i] = 0; }
Aalborg Media Lab 2-May-15 Random Number Generator Generating random numbers between 0 – 50, counting the occurrences of each number. Modify the range to (-25) – (25) Create a histogram of intervals of these numbers 0 – 10 | ****** 11 – 20 | **** 21 – 30 | ********** …
Aalborg Media Lab 2-May-15 Approach Generating number Random generator = new Random(); int num = generator.nextInt(51); Store the occurrence in the array occurences[num]++; 012… … 01001
Aalborg Media Lab 2-May-15 Exercises so far LectureExercises SD2 – , 2.5, 2.9, 2.11, 2.13, (2.15) SD3 – – 3.5 SD4 – , 4.8, 4.10 SD5 – , 5.2, 5.13 SD6 – SD8 – , 7.3, 7.6, 7.12