Arrays – Basics
task 1 – A very basic array
// Initialize a new integer-array, named "numbers" with a length of 3
int[] numbers = new int[3];
// Assign value to first element in the array
numbers[0] = 90;
// Assign value to second element in the array
numbers[1] = 150;
// Assign value to third element in the array
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
println(a);
println(b);
task 2 – An array with many random numbers
Initialize a new integer-array, named "numbers" with a length of 1000
int[] numbers = new int[1000];
Create a random number for every position in the array
for (int i = 0; i < numbers.length; i++){
numbers[i] = int(random(i));
}
print all the numbers of the array in the console
println(numbers[i]);