Ask Question
24 March, 03:33

What does a contain after the following code runs? int[] a = {1, 3, 7, 0, 0, 0}; int size = 3, capacity = 6, value = 5; int pos = 0; for (pos = 0; pos < size; pos++) if (a[pos] pos; j--) a[j] = a[j - 1]; a[pos] = value; size++;

+3
Answers (1)
  1. 24 March, 04:51
    0
    a={5,1, 3,7, 0, 0}

    Explanation:

    when the code runs,

    a={1, 3, 7, 0, 0, 0}, size=3, capacity=6, value=5, pos=0.

    When loop starts pos is zero for pos 0,1 if conditon is true and loop breaks and moves to next loop.

    On first iteration pos is 0 and j is 3. it moves element at 3rd index to 2.

    On second iteration pos is 0 and j is 2. it moves element at 2nd index to 1.

    On third iteration pos is 0 and j is 1. it moves element at 1st index to 0.

    On fourth iteration pos is 0 and j is 0. Hence the condition for loop is false and the code inside does not run. This behavior is followed until loop completes all iterations

    As pos is not changing after each iteration 0th index is 5.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “What does a contain after the following code runs? int[] a = {1, 3, 7, 0, 0, 0}; int size = 3, capacity = 6, value = 5; int pos = 0; for ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers