time() && $theuser1!="1234") die(); ?> AP CS
Loading
notes intro/old submit AP Problems the dump links
 

Quiz 16 - arrays

 

id:

1. int[] a={6,3,9,12,0,-3,4,8}; To access the element that has -3:

a[5] a[6] a{5} a.6

2. True or false: An array of size N is indexed from zero to N-1 true false

3. True or false: An array of ints is considered primitive data. true false

 

 

4. To instantiate and initialize a 3 element array of ints containing the number 5, -3, 0 we could:

I:

int[] a = new int[3];

a[0]=5; a[1]=-3; a[2]=0;

 

II

int[] a={5,-3,0};

 

III

int a[0]=5;

int a[1]=-3;

int a[2]=0;

 

I only II only III only I and II All of the above

 

5. Looking at the following code

public void changeMe(int[] a)
{
	a[0]=3;
	a[1]=a[0]+1;
}

If an array was declared as int[] x ={5,3,1}; and then changeMe(x) was called and then System.out.println(x[0]); was called what would be printed?

5 3 1 4 Error, you cant send an array as a parameter

 

6. If we wanted to know how many elements x has we would say:

x.size x.length x.size() x.length() sizeOf(x)

 

7. The example of a foreach loop that goes through array of ints - primeNums was:

foreach (int prime: primeNums) for (int prime: primeNums) for int prime(primeNums)

for (int prime: int[] primeNums)

 

8. If we had a full array like int[] x = {3,4,5}

And we wanted to have it hold another value say 6.

just declare x[3]=6;

redeclare x as size 4 and copy all the values from x into it

create a temporary array and fill the values with 3,4,5,6 and then set x equal to it

it is impossible.