Ask Question
11 April, 09:19

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. 11 April, 09: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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers