Ask Question
5 November, 21:27

What is stored in alpha after the following code executes?

int[] alpha = new int[5];

int j;

for (j = 0; j < 5; j++)

{

alpha[j] = j + 1;

if (j > 2)

alpha[j - 1] = alpha[j] + 2;

}

1. alpha = {1, 2, 3, 4, 5}

2. alpha = {4, 5, 6, 7, 9}

3. alpha = {1, 5, 6, 7, 5}

4. None of these

+2
Answers (1)
  1. 6 November, 01:25
    0
    3. alpha = {1, 5, 6, 7, 5}

    Explanation:

    Initially, we have that:

    alpha[0] = 1;

    alpha[1] = 2;

    alpha[2] = 3;

    alpha[3] = 4;

    alpha[4] = 5;

    For j higher than 2, we have that:

    alpha[j - 1] = alpha[j] + 2;

    So

    j = 3

    a[2] = alpha[3]+2 = 4 + 2 = 6;

    j = 4

    a[3] = alpha[4]+2 = 5+2 = 7;

    The correct answer is:

    3. alpha = {1, 5, 6, 7, 5}
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “What is stored in alpha after the following code executes? int[] alpha = new int[5]; int j; for (j = 0; j < 5; j++) { alpha[j] = j + 1; if ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers