int[][] mega = {{10,70,20,90}, {30,80}, {10}, {50, 70, 20}};
- Draw the memory diagram for the array
mega
. Clearly label all references and instances. HINT: you will have oneint[][] reference
, fourint[] reference
, oneint[][] instance
and fourint[] instance
. - Write a piece of code that stores the sum of all items of
mega
in a variabletotal
. - Write a piece of code that displays the items from last to first sub-array, and within each sub-array, last to first item.
- Write a piece of code that displays the items from last to first sub-array, and within each sub-array, first to last item.
- Write a piece of code that displays the items from first to last sub-array, and within each sub-array, last to first item.
Assume that the arrays posX
and posY
store co-ordinates of multiples circles. Each array contains the same number of items (and that number is greater than 0). posX[i], posY[i]
represents the position of the (i+1)th circle. Write a piece of code that shifts each circle up and right by 1 pixel each.
Please describe execution in as much detail as you can, avoiding the use of technical terminology (e.g state "a large white circle in the top right of the screen" as opposed to "a white ellipse of radius 500 centred at co-ordinates (300, 50)).
PVector pos[] = new PVector[11];
int dir[] = new int[11];
int speed = 5;
float dia = 20;
void setup() {
size(400, 400);
float k = 0;
for (int i = 0; i < pos.length; i++) {
pos[i] = new PVector(k, k);
dir[i] = 1;
k += 40;
}
}
void draw() {
background(0);
for (int i = 0; i < pos.length; i++) {
fill(255);
ellipse(pos[i].x, pos[i].y, dia, dia);
if (pos[i].y > height || pos[i].y < 0) {
dir[i] *= -1;
}
pos[i].y += dir[i] * speed;
}
}