Introduction to Programmingusing the Processing languageLecturer: Mark Huiskes of the Media Technology MSc program at Leiden University Teaching assistants: Amalia Kallergi, Hanna Schraffenberger Course developed by Bas Haring (2004) Alterations by Maarten Lamers (2005, 2006, 2007) Alterations by Mark Huiskes (2008, 2009) Introduction Lecture I Lecture II Lecture III Lecture IV Lecture V Lecture VI Lecture VII Handouts |
||
Programming concepts |
Arrays |
|
Reserved words |
[] .length
{} new
|
|
Example IV.1 |
This code shows the syntax of arrays. It declares
and initializes one array of integers, and prints its contents.
Note how the index value (variable i) can have value 0, but must
always remain smaller than a.length.
| |
int[] a = {23, 4, 19, 68};
print (a[0]);
print (" ");
println (a[1]);
for (int i=0; i < a.length; i++)
print (a[i] + " ");
println();
for (int i = a.length-1; i >= 0; i--)
print (a[i] + " ");
println();
|
||
Assignment IV.1 |
Make a program that prints the numbers 1 to 20 in random order, but prints each value
only once. |