Java

TOPIC 44 – ARRAYS 1

 

LESSON WORK

 

 

 

 

QUESTION #1 (SELF-CHECK)

 

SOLUTIONS

Fill in the blanks.

 

a)    The first element in an array has index number 0.

b)    The last element in an array containing 35 elements has index number 34.

c)     An array of length 12 will have elements with indexes ranging from 0 to 11.

d)    True or false?  If attempting to access the element with index 20 in an array of length 20, you will get an out of bounds error.  True

e)    The length of an array or the size of an array refers to the number of elements in the array.

f)      True or false?  An array in Java can be resized.  False

g)    True or false?  An array in Java can be given a size at run-time.  True

h)    For an array called data, we can check the number of elements in it by using data.length.

i)       The line int x; declares an integer variable named x.  What line of the code declares an integer array name numbers?  int[] numbers;

j)       If grades is a double array, then we can get a String representation for that array by using Arrays.toString(grades).