Slides 07
Slides 07
Slides 07
Arrays
Arrays
• Arrays are objects that help us organize large
amounts of information
0 1 2 3 4 5 6 7 8 9
scores 79 87 94 82 67 98 87 81 74 91
scores[2]
scores[first] = scores[first] + 2;
scores 79
87
94
82
67
98
87
81
74
91
• Note that the array type does not specify its size,
but each object of that type has a specific size
boolean[] flags;
flags = new boolean[20];
System.out.println (codes[count]);
scores.length
float[] prices;
float prices[];
• Examples:
words -
-
-
-
-
System.out.println (words[0]);
words “friendship
”“loyalty”
“honor”
-
-
Tunes CDCollection
- collection : CD[]
+ main (args : String[]) : void - count : int
- totalCost : double
- title : String 1
- artist : String
- cost : double
- tracks : int
*
+ toString() : String
if (list.length != 0)
{
int sum = 0;
for (int num : list)
sum += num;
result = (double)num / list.length;
}
return result;
}
one two
dimension dimensions
value = scores[3][6]
• Mouse Events:
mouse pressed the mouse button is pressed down