Java Ch 7 - Arrays

21 Questions | Total Attempts: 1487

SettingsSettingsSettings
Please wait...
Java Ch 7 - Arrays

The computer window and operating system are essential to the functioning of a computer. Java Chapter 7 – Arrays may not be as simple or complex as you think so just try it out and see for yourself.


Questions and Answers
  • 1. 
         Which of the following declares an array of int named beta?
    • A. 

      Int beta;

    • B. 

      Int[] beta;

    • C. 

      New int beta[];

    • D. 

      Int beta = int[];

  • 2. 
    Int[] numList = new int[50];   for (int i = 0; i < 50; i++)     numList[i] = 2 * i;   num[10] = -20; num[30] = 8;   How many components are in the array numList seen in the accompanying figure?
    • A. 

      0

    • B. 

      30

    • C. 

      49

    • D. 

      50

  • 3. 
    What is the index number of the last component in the array numList seen in the accompanying figure?
    • A. 

      0

    • B. 

      30

    • C. 

      49

    • D. 

      50

  • 4. 
    Which of the following is the array subscripting operator in Java?
    • A. 

      .

    • B. 

      { }

    • C. 

      New

    • D. 

      [ ]

  • 5. 
    Suppose you have the following declaration.   double[] salesData = new double[500];   Which of the following range is valid for the index of the array salesData. (i)  0 through 500 (ii) 0 through 499
    • A. 

      Only (i)

    • B. 

      Only (ii)

    • C. 

      Both i and ii

  • 6. 
    What is the output of the following Java code?   int[] list = {0, 5, 10, 15, 20};   for (int j = 0; j < 5; j++)     System.out.print(list[j] + " "); System.out.println();
    • A. 

      0 1 2 3 4

    • B. 

      0 5 10 15 20

    • C. 

      0, 5, 10, 15, 20

    • D. 

      0 5 10 15

  • 7. 
    What is the value of alpha[4] after the following code executes?   int[] alpha = new int[5];   for (int j = 0; j < 5; j++)     alpha[j] = 2 * j - 1;
    • A. 

      One

    • B. 

      Three

    • C. 

      Five

    • D. 

      Seven

  • 8. 
    What is stored in alpha after the following code executes?   int[] alpha = new int[5];   for (int j = 0; j < 5; j++) {    alpha[j] = 2 * j;      if (j % 2 == 1)       alpha[j - 1] = alpha[j] + j; }
    • A. 

      Alpha = {0, 2, 4, 6, 8}

    • B. 

      Alpha = {3, 2, 9, 6, 8}

    • C. 

      Alpha = {0, 3, 4, 7, 8}

    • D. 

      Alpha = {0, 2, 9, 6, 8}

  • 9. 
    Int[] list = {1, 3, 5, 7}; for (int i = 0; i < list.length; i++)     if (list[i] > 5)         System.out.println(i + " " + list[i]);   Which indices are in bounds for the array list, given the declaration in the accompanying figure?
    • A. 

      0, 1, 2, 3

    • B. 

      1, 2, 3, 4

    • C. 

      1, 3, 5, 7

    • D. 

      0, 1, 3, 5

  • 10. 
    Consider the following method definition.   public static int strange(int[] list, int listSize, int item) {    int count = 0;      for (int j = 0; j < listSize; j++)       if (list[j] == item)          count++;      return count; } Which of the following statements best describe the behavior of this method?
    • A. 

      This method returns the number of values stored in list.

    • B. 

      This method returns the sum of all the values of list.

    • C. 

      This method returns the number of times item is stored in list.

    • D. 

      This method can process an array of doubles.

  • 11. 
    Given the following method heading   public static void mystery(int list[], int size)   and the declaration   int[] alpha = new int[75];   Which of the following is a valid call to the method mystery?
    • A. 

      Mystery(alpha[75], 50);

    • B. 

      Mystery(alpha[], 50);

    • C. 

      Mystery(alpha, 40);

    • D. 

      Mystery(int[75], alpha)

  • 12. 
    How many objects are present after the code fragment in the accompanying figure is executed?
    • A. 

      1

    • B. 

      2

    • C. 

      7

    • D. 

      14

  • 13. 
    Char[][] table = new char[10][5];    How many dimensions are in the array seen in the accompanying figure?
    • A. 

      1

    • B. 

      2

    • C. 

      5

    • D. 

      10

  • 14. 
    Char[][] table = new char[10][5]; How many rows are in the array seen in the accompanying figure?
    • A. 

      0

    • B. 

      5

    • C. 

      10

    • D. 

      15

  • 15. 
    Char[][] table = new char[10][5]; What is the value of table.length?
    • A. 

      0

    • B. 

      5

    • C. 

      10

    • D. 

      15

  • 16. 
    Suppose that sales is a two-dimensional array of 10 rows and 7 columns wherein each component is of the type int. Which of the following correctly finds the sum of the elements of the fifth row of sales?
    • A. 

      Int sum = 0; for(int j = 0; j < 7; j++) sum = sum + sales[5][j];

    • B. 

      Int sum = 0; for(int j = 0; j < 7; j++) sum = sum + sales[4][j];

    • C. 

      Int sum = 0; for(int j = 0; j < 10; j++) sum = sum + sales[5][j];

    • D. 

      Int sum = 0; for(int j = 0; j < 10; j++) sum = sum + sales[4][j];

  • 17. 
    Arrays have a fixed number of elements.
    • A. 

      True

    • B. 

      False

  • 18. 
    A single array can hold components of many different data types.
    • A. 

      True

    • B. 

      False

  • 19. 
    The statement   int[] list = new int[15];   creates list to be an array of 14 components because array index starts at 0.
    • A. 

      True

    • B. 

      False

  • 20. 
    Given the declaration   double[] numList = new double[20];   the statement   numList[12] = numList[5] + numList[7];   updates the content of the thirteenth component of the array numList.
    • A. 

      True

    • B. 

      False

  • 21. 
    You can create an array of reference variables to manipulate objects.
    • A. 

      True

    • B. 

      False

Back to Top Back to top