int[] taxi = {10, 70, 20, 90};
- Draw the memory diagram that represents the reference and the instance. Clearly label each as reference and instance.
- What is the value of
taxi.length
? - What is the index of the last item?
- What do you get when you display
taxi[3]
? - What do you get when you display
taxi[0]
? - What do you get when you display
taxi[-1]
? - What do you get when you display
taxi[4]
?
- What is the index of the last item?
- What is the variable that gives you the value of the last item (for example,
cab[0]
gives you the first item)? - Write a statement that doubles the last item. For example, if the last item is 10, it should become 20.
- Write a statement that displays the last item, if any (do nothing if array is empty).
- Write a statement that doubles the last item, if any (do nothing if array is empty).
- that holds 200 integer values.
- that holds 5000 salaries (think about the data type).
- that holds, for a binary image, values of 240000 pixels (think about the data type).
- that holds the values 10, 70, 20, 90, 30, 80, 40, 70.
- that holds the values 10, 70, 20, 90, 30, 80.6, 40, 70.
For an arbitrary array cab
that contains 0 or more integer values (but is definitely not null
), write a piece of code that,
- displays items of the array, each on a different line
- stores the sum of all items in a variable
total
- stores the number of positive items in a variable
countPositives
- stores the sum of all odd items in a variable
sumOdds
int[] a = {10, 70, 20, 90};
int[] b = {50, 30, 80};
int[] c = a;
a = b;
b = c;
int result = a[0]+b1-c[2];
For example, for the following arr, the sum will be 135
:
int arr[] = {10, 30, 50, 45};
int[] foo = {20, 2, 5, 1, 10, 3, 9};
int[] bar = {0, 9, 32, 59, 2, 5, 8};