What is the value of alpha[3] after the following code executes?int[] alpha = new int[5];int j;alpha[0] = 5;for (j = 1; j < 5; j++){if (j % 2 == 0)alpha[j] = alpha[j - 1] + 2;elsealpha[j] = alpha[j - 1] + 3;}1. None of these2. 133. 154. 10

Respuesta :

Answer:

Option 2: 13

Explanation:

Given the code as follows:

  1.        int[] alpha = new int[5];
  2.        int j;
  3.        alpha[0] = 5;
  4.        for (j = 1; j < 5; j++)
  5.        {
  6.            if (j % 2 == 0)
  7.                alpha[j] = alpha[j - 1] + 2;
  8.            else
  9.                alpha[j] = alpha[j - 1] + 3;
  10.        }

The alpha is an array with size of 5.

The first element of the array has been initialized to 5 (Line 3).

Within the for loop (4 - 10), there is if and else statements that check if the current index j (starting from 1 to 4) is an odd or even number.

If j = 1, the else statement (Line 9) will run and set the alpha[1] to alpha[1-1] + 3 = 5 + 3 = 8

If j = 2, the if statement (Line 7) will run and set the alpha[2] to alpha[2-1] + 2 = 8 + 2 = 10

If j = 3, the else statement will run and set the alpha[3] to alpha[3-1] + 3 = 10 + 3 = 13  

Answer:

Explanation:

give that person brainlist

ACCESS MORE