forked from processing-js/processing-js.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray.html
More file actions
141 lines (57 loc) · 2.56 KB
/
Copy pathArray.html
File metadata and controls
141 lines (57 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
---
layout: default
---
<table cellpadding="0" cellspacing="0" border="0" class="ref-item">
<tr class="name-row">
<th scope="row">Name</th>
<td><h3>Array</h3></td>
</tr>
<tr class="">
<th scope="row">Examples</th>
<td><div class="example"><pre>int[] numbers = new int[3];
numbers[0] = 90;
numbers[1] = 150;
numbers[2] = 30;
int a = numbers[0] + numbers[1]; // Sets variable a to 240
int b = numbers[1] + numbers[2]; // Sets variable b to 180</pre></div><hr class="noShade" noshade="noshade" size="1" /><div class="example"><pre>int[] numbers = { 90, 150, 30 };
int a = numbers[0] + numbers[1]; // Sets variable a to 240
int b = numbers[1] + numbers[2]; // Sets variable b to 180</pre></div><hr class="noShade" noshade="noshade" size="1" /><div class="example"><pre>int degrees = 360;
float[] cos_vals = new float[degrees];
for(int i=0; i < degrees; i++) {
cos_vals[i] = cos(TWO_PI/degrees * i);
}</pre></div></td>
</tr>
<tr class="">
<th scope="row">Description</th>
<td>An array is a list of data. It is possible to have an array of any type of data. Each piece of data in an array is identified by an index number representing its position in the array. The first element in the array is <b>[0]</b>, the second element is <b>[1]</b>, and so on. Arrays are similar to objects, so they must be created with the keyword <b>new</b>. Every array has a variable <b>length</b> which is an integer value for the total number of elements in the array. (People are often confused by the use of <b>length()</b> to get the size of a String and <b>length</b> to get the size of an array. Notice the absence of the parentheses when working with arrays.)</td>
</tr>
<tr class="">
<th scope="row">Syntax</th>
<td><pre><kbd>datatype</kbd>[] <kbd>var</kbd><kbd>var</kbd>[<kbd>element</kbd>] = <kbd>value</kbd><kbd>var</kbd>.length</pre></td>
</tr>
<tr class="">
<th scope="row">Parameters</th>
<td><table cellpadding="0" cellspacing="0" border="0">
<tr class="">
<th scope="row">datatype</th>
<td>any primitive or compound datatype, including user defined classes</td>
</tr>
<tr class="">
<th scope="row">var</th>
<td>any valid variable name</td>
</tr>
<tr class="">
<th scope="row">element</th>
<td>int: must not exceed the length of the array - 1</td>
</tr>
<tr class="">
<th scope="row">value</th>
<td>data to assign to the array element, must be the same datatype as the array</td>
</tr>
</table></td>
</tr>
<tr class="">
<th scope="row">Usage</th>
<td>Web & Application</td>
</tr>
</table>