Make your own free website on Tripod.com

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[])

            


HOME