# Aalborg Media Lab 2-May-15 Exercises/Summary Lecture 10 Summary, Exercises.

## Presentation on theme: "Aalborg Media Lab 2-May-15 Exercises/Summary Lecture 10 Summary, Exercises."— Presentation transcript:

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 0 1 2 3 4 5 6 7 8 9 79 87 94 82 67 98 87 81 74 91 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 01234 0 scores for (int i = 0; i < scores.length; i ++) { scores[i] = 0; } 01234 00 01234 000 01234 0000 01234 00000 01234

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…50 00000 012… 01001

Aalborg Media Lab 2-May-15 Exercises so far LectureExercises SD2 – 06.092.3, 2.5, 2.9, 2.11, 2.13, (2.15) SD3 – 13.093.1 – 3.5 SD4 – 13.094.1, 4.8, 4.10 SD5 – 20.095.1, 5.2, 5.13 SD6 – 20.096.14 SD8 – 27.097.2, 7.3, 7.6, 7.12

Download ppt "Aalborg Media Lab 2-May-15 Exercises/Summary Lecture 10 Summary, Exercises."

Similar presentations