Creating an Array with 20 Double Elements Quiz
8 Questions
1 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

Which of the following is the correct way to create an array with 20 double elements?

  • double[] array = new double[20]; (correct)
  • double array = new double[20];
  • c. double[20] array = new double[];
  • d. double[] array = new array[20];
  • Given the declaration below, what is the value of array[3]? int[] array = {4, 3, 5, 2, 0};

  • 5
  • 2 (correct)
  • 0
  • 3
  • Given the declaration below, which of the following statements would cause a run- time error?

    int[] array = {4, 3, 5, 2, 0};

  • a. array[5] = 1; (correct)
  • b. array[2] = array[3];
  • c. array[0] = 1;
  • d. array[4] = 1;
  • What output is generated by the code segment below?

    int[] values = new int[10]; for (int k = 0; k < values.length; k++) { values[k] = k * 2; } System.out.println(values[5]);

    <p>10</p> Signup and view all the answers

    Insert the missing statement in the following code fragment, which is designed to initialize the array elements with the values 1, 2, 3, . . . , 100.

    int[] numbers = new int[100]; for (int k = 0; k < numbers.length; k++) {

    }

    <p>a. numbers[k] = k + 1;</p> Signup and view all the answers

    What output is generated by the code fragment below?

    int[] values = { 1, 3, 1, 3, 1 }; int[] numbers = values; for (int k = 0; k < values.length; k++) { values[k] = k * 2; } System.out.print(values[2]); System.out.print(" " + numbers[2]);

    <p>4 4</p> Signup and view all the answers

    What output is generated by the program segment below?

    int[] values = { 1, 3, 5, 3, 7 }; int count = 0; for (int number : values) { if (number > 4) { count++; }

    } System.out.print(count);

    <p>2</p> Signup and view all the answers

    Complete the code fragment below by inserting the statement that makes the most appropriate use of the enhanced for loop.

    int[] values = { 1, 3, 5, 3, 7 }; for (int number : values) {

    }

    <p>d. System.out.println(number);</p> Signup and view all the answers

    More Like This

    Arrays Records Lists &amp; Tuples
    5 questions
    Arrays in Computer Programming 2
    12 questions
    Arrays in Python
    10 questions

    Arrays in Python

    RationalPalladium6063 avatar
    RationalPalladium6063
    Use Quizgecko on...
    Browser
    Browser