 ## Topic 8 - Sample Questions - Arrays (10 days)

1. Write a function that will let you enter numbers into an array.

Āpublic staticĀvoid enter(int ar[])

Ā

2. Write a function that will print out the elements in an array.

ĀĀpublic staticĀvoid print (int ar[])

Ā

3. Write a function that will return the sum of the numbers in an array.

ĀĀĀ int getsum(int ar[])

Ā

4. Return biggest number in an array.

ĀĀĀĀ public staticĀint getbiggest(int ar[])

Ā

5. Find average of numbers in an array.

ĀĀĀĀ public staticĀdouble getavg(int ar[])

Ā

6. Print vector in reverse order.

ĀĀĀĀ public staticĀvoid printreverse(int ar[])

Ā

7. Print every other element in the vector.

ĀĀĀĀ public staticĀvoid printeveryother (int ar[])

Ā

8. Return true if average of grades in array >= 90.

ĀĀĀĀĀ public staticĀboolean honors (int ar[])

Ā

9. Return letter grade associated with average.

ĀĀĀ public staticĀString grade(int a[])

Ā

10. Return how many odd numbers were in the array.

ĀĀĀĀ public staticĀint countodd(int ar[] )

Ā

11. Print out elements in second half of array only.

ĀĀ public staticĀvoid printhalf(int ar[])

Ā

12. Return average of odd numbers in array.

ĀĀĀĀ public staticĀdouble avgofodd(int ar[])

Ā

13. Change any odd numbers to next even number.

ĀĀ public staticĀvoid change(int ar[])

Ā

14. Sort the array into ascending order using a bubble sort (selection, insertion)

ĀĀĀ public staticĀvoid sort(int ar[])

Ā

15. Enter numbers into array until you enter a -1. Return ct. Array is already sized big enough to hold numbers entered.

ĀĀĀ public staticĀint enter(int ar[] )

ĀĀ // precondition ar.length() is initially == 0

Ā

16. Switch every other element in the array.

Ā public staticĀvoid switch (int ar[])

Ā

17. Return the average deviation. You must call function getavg (#5).

ĀĀ public staticĀdouble avgdeviation(int ar[])

Ā

18. Return location ofĀ first occurence of number in a array. Return -1 if number is not there.

ĀĀ public staticĀint linear(int ar[], int num)

Ā

19. Count the number of occurences of a number in a array.

public staticĀĀĀĀ nt count(int ar[], int num)Ā

Ā

20. Shift numbers in array so that first number is gone.

ĀĀ public staticĀvoid shift(int ar[])

Ā

21. Change array so everyone shifts down one spot and one in last spot goes into first position.

ĀĀ public staticĀvoid shift2(int ar[])

Ā

22. Given parallel array of names and phone numbers print out the phone number for a given name or a message that the person is not in the list.

Ā public staticĀvoid printphone(String [] na, String[] te, String name)

Ā

23. Write a function that will return true if a number is in the array.

ĀĀĀ public staticĀboolean isthere(int ar[], int num)

Ā

24. Write a function that will fill a array of predetermined size with random numbers between 1 and 100.

Ā public staticĀvoid fill(int ar[])

25. Write a function that will double the size of the array.

public staticĀvoid doublesize(int ar[])

ĀĀĀĀĀĀĀĀĀĀĀĀ