Ask Question
13 February, 17:45

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

+1
Answers (1)
  1. 13 February, 18:50
    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?
Get 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 & 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